基本的UI控件和布局文件

    技术2024-07-31  65

    文本控件 -TextView -EditText 按钮控件 - Button -ImageButton 状态开关按钮 -ToggleButton 单选与复选按钮 -CheckBox - RadioButton 图片控件 -ImageView 时钟控件 -AnalogClock -DigitalClock 日期与时间选择控件 -DataPicker -TimePicker 布局文件: LinearLayout和RelativeLayout 共有属性: java代码中通过btn1关联次控件 android:id=" @ +id/btn1" 控件宽度. android:layout width=”80px" //”80dip” 或”80dp” android:layout width = "wrap content" android:layout width = "match_ parent" 控件高度 android:layout_ height=" 80px" //”80dip"或”80dp" android:layout_ height = "wrap_ content" android:layout_ height = "match_ _parent" 控件排布 android:orientation=" horizontal" android:orientation=" vertical “ 控件间距 android:layout_ marginLeft=" 5dip”//距离左边 android:layout_ marginRight=" 5dip”//距离右边 android:layout_ marginTop=" 5dip" //距离.上面 android:layout_ marginRight=" 5dip”//距离 下面 控件显示位置 android:gravity="”center”//left,right, top, bottom android:gravity=" center_ horizontal" android:layout_ gravity是本元素对父元索的重動向。 android:layout gravity属性则设置控件本身相对于父控件的显示位置 android:gravity是本元素所有子元素的重向。 android:layout_ gravity=" center _vertical" android:layout_ gravity=" left" android:layout_ gravity=”left|bottom" TextView中文本字体 android:text=" @String/text1” //在string.xml中定 义text1的值 android:textSize=" 20sp' android:textColor=" #ff123456" android:textStyle=" bold" //普通 (normal) ,斜体(italic) ,粗斜体(bold italic) 定义控件是否可见 android:visibility=" visible" /何观. android:visbility=" invisible" //不可见,但是在布局中占用的位置还在 android:visibility=”gone" /不可见,完全从布局中消铁 义背景图片 android:background=”@drawable/img_ bg”//img_ bg为drawable 下的一张图片 seekbar控件背景图片及最大值 android:progressDrawable=" @drawable/seekbar_ img" android:thumb=" @drawable/thumb' android:max = "60" 仅在RelativeLayout中有效: 在父亲布局的相对位置 android:layout alignParentLeft=" true”//在布局左边 android:layout_ alignParentRight=" true" //在布局右边 android:layout_ alignParentTop=" true" //在布局_上面 android:layout_ alignParentBottom=" true ”//在布局的下面 在某个控件的相对位置 android:layout_ toRightOf=" @id/button1” //在控件button1的右边, 不仅仅是紧靠着 android:layout_ toLeftOf=" @id/button1”//在控件button2的左边, 不仅仅是紧靠着 android:layout_ below=" @id/button1 ” //在控件button1下面,不仅仅正下方 android:layout above= "@id/button1" //在控件button1 下面,不仅仅是正下防 定义和某控件对奇 android:layout_ alignTop=" @id/button1” //和控件button1 上对齐 android:layout_ alignBottom=”@id/button1" //和控件button1 下对齐

    android:layout alignLeft=" @id/button1” /和控件button1左对齐 android:layout alignRight=" @id/button1” //和控件button2右对齐 android:layout_ centerHorizontal=" true” //水平居中 android:layout_ centerVertical=" true" android:layout_ centerInParent=" true" 仅在LinearLayout中有效 设置控件在一排或- 列中所占比例值 android:layout_ weight=" 1”  

    Processed: 0.015, SQL: 9