学习笔记第一弹UI"/>
Android学习笔记第一弹UI
趁着周末,好好整理这两周的学习成果。实习的压力啊
fill_parent和 wrap_content 的区别
1.fill_content是指控件尽可能的扩展以填充满布局单元,
2.wrap_content是指控件尽可能的显示控件内容,必要时可以根据内容更改大小。
LinearLayout布局,可以有垂直线性布局和水平线性布局,android:orientation分别为
vertical 和horizontal
TableLayout:
TableLayout没有边框,由多个TableRow对象组成,每个TableRow又由0个或多个单元格,每个单元格就是一个View,
为textView设置 android:visibility="invisible",可以让单元格不可见,
设置TextView文字右对齐。
android:gravity="right"
设置TextView隐藏 android:visibility="invisible"
设置TextView宽度 android:width="205dp"
合并单元格 android:layout_span="3"
间隔线
<View android:layout_height="2dip" android:background="#F00" />
细节: 可以设置android:shrinkColumns 和android:shrinkColumns 设置收缩和伸张效果。
<EditView>: 属性:
1.android:minLine :设置输入框最小行数
网格布局:android4.0之后才出现的
GirdLayout: 网格布局默认是水平布局,但可以在 <GridLayout>标签里增加 android:ColumnCount=”” 和 android:RowCount=”” 属性。指定网格行列数量。另外,对于网格的子空间,默认是按照wrap_content排列的。
在网格内部,我们可以在子控件里指定 android:layout_row 和android:layout_column 指定位置, 当控件需要跨越多行或多列时,可以指定android:layout_rowSpan和android:layout_columnSpan属性。
网格布局要注意的点。有时候设置 android:layout_row 和android:layout_column 不起作用,需要对android:gravity属性进行设置,fill or fill_vertical or fill_horizontal就能显示想要的组件填充效果。这个点在做简单计算器中纠结了很久。
高级界面组件
☞图片组件,
ImageButton(图片按钮组件),属性中src和background是最为重要的两个属性,src表示图标在按钮中间部分显示图片,background表示背景,在整个按钮中显示图片。
ImageSwitcher(图片切换器),
Gallery(图片轮播器):以弃用
ListView
listView显示需要条目xml布局文件,之后在布局文件成员变量里赋予R.java中的 listView资源。
适配器分为两种。
1.SimpleAdapter(简单适配器)。 SimpleAdapter类的构造方法(Context context,List<HashMap<String,Object > > data,Resource int,String []s1,int[] s2); 是将list中的数据绑定到Resource显示资源上。绑定的标志为 HashMap的key绑定到 view的Id上。
2.SimpleCursorAdapter(); 类构造器:SimpleCursorAdapter(content,Resource,cursor,new String[] s1,int[] ResourceId).. 但注意:Cursor中必须要Cursor中必须要有 _id 字段
3.自定义适配器 继承 BaseAdapter; 常用方法
a) getCount(); 返回子路总数
b) getItem(int position);
c) getView();
d) getItemId(int position)
里面用到了 LayoutInflater类(布局填充服务)
通过listView.setAdapter(Adapter);给ListView 传递若干个view
更多推荐
Android学习笔记第一弹UI
发布评论