Annroid交互式视觉设计控件一
View常用属性
-
控件的宽高:(固定值 与两种状态)
android:layout_width=“30dp”
android:layout_height=“30dp”
或
match_parent (fill_parent)填充满父布局
或
wrap_content包裹内容 -
控件的可见度:(3种状态)
android:visibility="visible"可见 gone完全消失 invisible消失但占位置 -
控件的背景:(颜色 或 图片)
android:background="#F00" 直接赋颜色值
@android:color/颜色 用系统自带颜色
#000000 @color/colorBlack 使用color.xml
图片 @mipmap/aaa -
盒子模型:
android:layout_margin=“10dp”
android:padding=“5dp” -
点击事件:
android:onClick="haha -
重力:控制控件内部所有的内容向某方向对齐
android:gravity =””;left right bottom top center center_vertical center_horizontal -
android:layout_gravity=“” 控制自己视图出现的位置
View和ViewGroup的关系
1.线性布局
重要属性:
指定方向:(横向布局/纵向布局) android:orientation=""
权重:android:layout_weight="" (只能在LinearLayout的子控件中使用)
2.相对布局(相对父控件布局 相对兄弟控件布局)
针对父控件
android:layout_centerHorizontal 横向居中
android:layout_centerVertical 纵向居中
android:layout_centerInParent 横向纵向居中
跟父控件顶部/底部/最左边/最右边对齐
android:layout_alignParentTop
android:layout_alignParentBottom
android:layout_alignParentLeft
android:layout_alignParentRight
针对已存在的兄弟控件(在某个控件的上面/下面/左边/右边)
android:layout_above
android:layout_below
android:layout_toLeftOf
android:layout_toRightOf
相对兄弟控件的边对齐
android:layout_alignTop
android:layout_alignBottom
android:layout_alignLeft
android:layout_alignRight
3.FrameLayout: 帧布局 越是后面写的控件越在顶层 (应用场景: 霓虹灯 自定义一些高级的UI控件) 层层叠加
4.AbsoluteLayout :绝对布局 控件在父控件中的绝对定位 (应用场景: 机顶盒开发 )
android:layout_x=“30dp”
android:layout_y=“30dp”
5.TableLayout: 表格布局 (应用场景: 银行表格)
常用属性:
(1)collapseColumns=“0,2”:隐藏列,隐藏第一和第三列
(2)stretchColumns=“1”:拉伸列
(3)shrinkColumns=“1”:收缩列
表格标签
表格行标签 该标签可以不使用
6.网格布局 GridLayout
行数:android:rowCount=“6”
列数:android:columnCount=“4”
跨列数:layout_columnSpan=“2”
跨行数:layout_rowSpan=“2”
列权重:layout_columnWeight=“1”
行权重:layout_rowWeight=“1”
四.什么是控件
界面控件指可在窗体上放置的可视化图形“元件”,“组件“,如按钮、文件编辑框等。其中大多数是具有执行功能或通过“事件”引发代码运行并完成响应的功能