注:任何View的属性
id
:指定idlayout_width
:宽度layout_height
:高度text
:文字textSize
:文字大小background
:背景(图片或颜色)layout_gravity
:相对父视图位置gravity
:内部位置padding
:内边距layout_margin
:外边距- 其他
一,LinearLayout
oritation
:方向
- vertical:垂直布局
- horizontal:水平布局
layout_weight
:权重
- 默认为0,大小为包裹内容
- >0时空间分割,大小为剩余空间按比例分配
二,RelativeLayout
1.兄弟视图之间
同向对齐
layout_alignXxx(Left,Rigth,Top,Bottom)
反向对齐
layout_toLeftOf
layout_toRightOf
layout_above
layout_below
2.父子视图之间
同向对齐
layout_alignParentXxx(Left,Rigth,Top,Bottom)
居中对齐
layout_centerInParent
layout_centerVertival
layout_centerHorizontal
三,FrameLayout
- 每一个子View代表一个画面
- 默认以屏幕左上角作为(0,0)坐标
- 按定义顺序覆盖显示
- 通过
layout_gravity
来指定位置
四,ListView
1.图示
Data+ItemLayout——(Adapter)—–>ListView
- 显示列表:listView.setAdapter(adapter)
- 更新列表:adapter.notifyDataSetChanged()
2.Adapter
ArrayAdapter:数据为List<String>或String[ ]
new ArrayAdapter<String>(Context context,int resource,String[] data)
resource:item的布局文件标识
data:数据集合
SimpleAdapter:数据为List<Map<String,Object>>
new SimpleAdapter(Context context,List<? extends Map<String,?>> data,int resource,String[] from,int[] to)
data:数据集合
resource:item布局文件标识
from:map中key的数组,用于得到对应的value
to:item布局文件中子View的id数组,与from对应
BaseAdapter:数据为List<Object>
构造一个MyAdapter实现BaseAdapter的abstract方法:
public int getCount()
:集合中元素数量
public Object getItem(int position)
:返回集合中对应位置数据
public long getItemId(int position)
:不详
public View getView(int position,View convertView,ViewGroup parent)
:返回对应position的item的View对象
convert:缓存的Item的View对象(当一个View不可见时,被放入缓存)
parent:ListView对象
SimpleCursorAdapter:数据为数据库查询结果集
待续
五,GridView
与ListView配置类似
GridView+Adapter+data+layout
六,Style和theme
Style
- 多个视图属性的集合,便于复用
- 定义为sytles.xml文件中的一个Style
- 在布局文件中使用@style/style_name引用
- 使用系统样式@android:sytle/xxx
<style name="Mystyle">
<item name="field_name1" >field_value1</item>
<item name="field_name1" >field_value2</item>
</style>
Theme
- theme的本质也是style,定义在styles.xml中
- 在manifest.xml文件中引用
android:theme="@style/AppTheme" >
- 针对某个应用或某个Activity界面
常用系统主题
- @android:style/Theme.Light.NoTitleBar:没有标题
- @android:style/Theme.Light.NoTitleBar.FullScreen:全屏
- @android:style/Theme.Dialog:对话框