實驗中只需要編寫相應的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>
新聞熱點
疑難解答
圖片精選