实验中只需要编写相应的xml的代码,java代码不需要更改,因为我们这里只是练习android的界面设计。
线性布局:
线性布局就是将各种控件按照行或者列依次进行排列。
其中本实验用到的各控件的属性解释如下:
android:layout_weight属性是指不同的控件在activity中占有体积大小的比例。
android:paddingleft指内边距左的距离,即控件内文字离控件左边边界的距离。其它的类推。
android:gravity指控件内文字相对于控件本身的方向属性,长度为dip,与像素独立的长度。
android:background为控件内文字颜色的背景色,颜色采用rgb时前面需用”#”号.
android:textsize为文本的大小,单位为pt,即镑。
android:id为该控件的id,即在此处可以设置控件的id。
android:layout_width为控件本身的宽度属性,其它的类似。
实验结果显示2行字,分别设置了不同的属性。
效果如下:
xml代码如下:
</linearlayout>
xml代码如下:
</tablelayout>
xml代码如下:
<linearlayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1" >
<textview
android:id="@+id/london"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="伦敦奥运"
android:textsize="5pt"
android:background="#00ff00"
android:gravity="center_horizontal"
android:padding="10pt"
android:layout_weight="1"
/>
<textview
android:id="@+id/china"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="中国加油!!!"
android:textsize="8pt"
android:background="#ff00ff"
android:layout_weight="3"
/>
</linearlayout>
<linearlayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3">
<tablelayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchcolumns="1"
>
<tablerow>
<textview
android:text="国家"
android:background="#848484"
android:padding="2dip"
/>
<textview
android:text="金牌"
android:background="#ff0000"
android:padding="2dip"
/>
<textview
android:text="银牌"
android:background="#00ff00"
android:padding="2dip"
/>
<textview
android:text="铜牌"
android:background="#0000ff"
android:padding="2dip"
/>
</tablerow>
<tablerow >
<textview
android:text="中国"
android:background="#848484"
android:padding="2dip"
/>
<textview
android:text="*"
android:background="#ff0000"
android:padding="2dip"
/>
<textview
android:text="**"
android:background="#00ff00"
android:padding="2dip"
/>
<textview
android:text="***"
android:background="#0000ff"
android:padding="2dip"
/>
</tablerow>
<tablerow >
<textview
android:text="美国"
android:background="#848484"
android:padding="2dip"
/>
<textview
android:text="*"
android:background="#ff0000"
android:padding="2dip"
/>
<textview
android:text="**"
android:background="#00ff00"
android:padding="2dip"
/>
<textview
android:text="***"
android:background="#0000ff"
android:padding="2dip"
/>
</tablerow>
</tablelayout>
</linearlayout>
</linearlayout>
如对本文有疑问, 点击进行留言回复!!
Xamarin 安卓 相机 各种坑 目标API Android 6以后,我选的目标API版本是 Android 10
Android 9.0+软件某些功能突然暴毙:cleartext not permitted
Android : Resource is not a Drawable (color or path)
Flutter问题集锦——Android Studio 4.0.1 在AVD Manger中启动模拟器报“unable to locate abd”
网友评论