Android ApiDemos樣本解析(142):Views->Layouts->Line

來源:互聯網
上載者:User

所有的ViewGroup(Layout類的基類)都包含width 和height 屬性(layout_width 和layout_height),所有的View都必須定義這兩個值。

layout_width 和layout_height 允許使用絕對值來定義(如像素值),當為了使UI能夠自適應螢幕大小,一般不使用絕對值來定義View的寬度和高度。可以使用如下兩個常量:

wrap_content:  告訴View使用能包含其內容的尺寸 (類似於WinForm 中AutoSize)。
fill_parent(或match_parent 從Level 8起): 子View擴充為其父容器尺寸。
本例和上例的不同之處在於本例為LinearLayout設定了match_parent ,因此此LinearLayout將充滿螢幕:

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:background=”@drawable/blue”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<!– view1 goes on top –>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_2_top”/>

<!– view2 goes in the middle –>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_2_middle”/>

<!– view3 goes on the bottom –>
<TextView
android:background=”@drawable/box”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_2_bottom”/>

</LinearLayout>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.