Android 之布局(二)

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   ar   使用   sp   java   

3、TableLayout(表格版面配置)

像表格一樣布局,通常情況下,TableLayout有多個TableRow組成,每個TableRow就是一行。

<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:shrinkColumns="2">    <TableRow>        <Button android:text="Button1"/>        <Button android:text="Button2"/>        <Button android:text="Button3"/>    </TableRow>    <TableRow>        <Button android:text="Button4"/>        <Button android:text="Button5"/>        <Button android:text="Button6"/>    </TableRow>    <TableRow>        <Button android:text="Button7"/>        <Button android:text="Button8"/>        <Button android:text="Button9"/>    </TableRow></TableLayout>

 

總結:常用屬性:

[1]shrinkColumns屬性:以0行為序,當TableRow裡面的控制項布滿布局時,指定列自動延伸以填充可用部分;當TableRow裡面的控制項還沒有布滿布局時,shrinkColumns不起作用。(android:shrinkColumns="2",第3列布滿時填充)

[2]strechColumns屬性:以第0行為序,指定列對空白部分進行填充。(android:strechColumns="2",第3列填充)

[3]collapseColumns屬性:以0行為序,隱藏指定的列.。(android:strechColumns="2",隱藏第3列)

[4]layout_column屬性:以0行為序,設定組件顯示指定列。(android:layout_column="2",顯示在第三列)

[5]layout_span屬性:以第0行為序,設定組件顯示佔用的列數。(android:layout_span="3",佔用3列)

4、AbsoluteLayout(絕對布局)

        組件的位置可以準確的指定其在螢幕的x/y座標位置。雖然可以精確的去規定座標,但是由於代碼的書寫過於剛硬,使得在不同的裝置,不同解析度的手機行動裝置上不能很好的顯示應有的效果,所以此布局不怎麼被推薦使用。

<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >    <Button         android:layout_width="wrap_content"        android:layout_height="fill_parent"        android:text="Button1"        android:layout_x="100dp"        />    <Button         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="Button2"        android:layout_y="100dp"        />    </AbsoluteLayout>

5、FrameLayout(單幀布局)

      據說是五種布局中最簡單的一種,因為單幀布局在新定義組件的時候都會將組件放置螢幕的左上方,即使在此布局中定義多個組件,後一個組件總會將前一個組件所覆蓋,除非最後一個組件是透明的。

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >    <Button         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="Button1"        />    <Button         android:layout_width="wrap_content"        android:layout_height="fill_parent"        android:text="Button2"        />    <Button         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Button3"        />    </FrameLayout>

 

Android 之布局(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.