展会信息港展会大全

Android ApiDemos示例解析(150):Views->Layouts->LinearLayout->10. Background Image
来源:互联网   发布日期:2015-10-13 15:31:55   浏览:1872次  

导读:上一篇:http://www.2cto.com/kf/201209/152591.html利用LinearLayout 可以将几个相关的UI空间构成一个组,将android:addState...

上一篇:http://www.2cto.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好像是一个整体:

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港