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

來源:互聯網
上載者:User

上一篇:http://www.bkjia.com/kf/201209/152591.html

利用LinearLayout 可以將幾個相關的UI空間構成一個組,將android:addStatesFromChildren設為True,這樣當組中的EditText或是Button擷取Focus時,將Layout的BackgroundImage設定成相應EditText或的Button的Drawable (按下,擷取Focus) ,此時整個Layout 的drawable 狀態和有和其子EditText或是Button的顯示效果,給使用者的感覺這個Layout中的View為一個整體。

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:addStatesFromChildren=”true”
android:gravity=”center_vertical”
android:paddingRight=”0dip”
android:background=”@android:drawable/edit_text”>

<!–
TextView label goes at the left.
–>
<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/linear_layout_10_to”
android:textColor=”?android:attr/textColorSecondary”
android:textAppearance=”?android:attr/textAppearanceLargeInverse”
/>

<!–
EditText goes in between.
–>
<EditText
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_weight=”1″
android:singleLine=”true”
android:background=”@null”
/> www.2cto.com

<!–
The button goes at the right.
–>
<ImageButton
style=”@android:style/Widget.Button.Inset”
android:src=”@android:drawable/star_big_on”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginTop=”2dip”
android:layout_marginRight=”2dip”
android:layout_marginBottom=”2dip”
android:padding=”10dip”
/>

</LinearLayout>

本例的LinearLayout 中子ViewEditText可以擷取焦點,將LinearLayout 的background設成@android:drawable/edit_text 和EditText的Drawable,並且android:addStatesFromChildren=”true”,這樣當EditText擷取焦點時, 顯示效果為整個Layout擷取焦點。這三個子View好像是一個整體:

 

聯繫我們

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