Android中文API-Include标签
来源:互联网 发布:ubuntu squid 配置 编辑:程序博客网 时间:2024/05/16 04:55
虽然,Android提供了多种多样的可重用轻量级的交互元素(如:TextView 等控件),但是你可能也想重用一些相对较大的特殊布局xml。为了有效的重用布局文件,你可以使用include标签和merge标签,是特殊的布局文件嵌入当前的布局。
可重用的布局是特别强大的。例如一个包含确定和取消的button面板,或者伴随着文案的自定义进度条(progressbar )。这就意味了一款应用中,复杂布局中共同的部分都可以被提取出来,独立管理,然后以include的方式,嵌入需要它的地方。所以,你也可以通过自定义View的方式创建一个独立的UI组件,这样使用起来,比通过include的方式更加简单。
Create a Re-usable Layout
创建一个可重用的布局文件。(titlebar.xml
)
<FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/titlebar_bg">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gafricalogo"/>
</FrameLayout>
为了让这个文件可以在任何一个添加了它的布局文件中展示,这个root View应该是准确的。
Use the <include> Tag
Here's the layout file:
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_bg"
android:gravity="center_horizontal">
<include layout="@layout/titlebar"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:padding="10dp"/>
...
</LinearLayout>
你也可在include标签中重写任何被重用的view的root view的(android:layout_*
)属性。例如:
<include android:id="@+id/news_title" android:layout_width="match_parent" android:layout_height="match_parent" layout="@layout/title"/>
然而,你一旦重写,你必须要重写android:layout_height
and android:layout_width
这两个属性,才能让它生效。
作者有话说:如果您需要Android中文API,请扫一扫下面的二维码,您的关注,就是我的动力。
- Android中文API-Include标签
- Android中文API- <merge/> 标签
- android include 标签
- Android include 标签
- Android include 标签
- Android include标签
- android的include标签
- Android include标签
- Android include标签
- Android include标签
- android include标签
- android: include标签注意事项
- android include标签学习
- android Include标签
- Android include标签
- android include merge标签
- android include标签使用
- android 的include标签
- C/C++预习:数字逆序输出(2,折半)
- Argument list too long 参数太长问题
- 图解oracle jdeveloper 代码智能提示+字体+编码 配置方法
- 判断手机网络状态
- Qt乱码处理过程
- Android中文API-Include标签
- 一个话务员给n个人打了n次电话,但是话务员记性不好,没记得给谁打过,没接到电话的人占总人数的多少
- JSP简单介绍
- hdu 1029 Ignatius and the Princess IV
- C++第四次作业-1000以内偶数和和乘法口诀表
- 内存泄露之--JDK6里的subString()方法
- Ubuntu 16.10下源码安装nginx的步骤
- Oracle未启用Partitioning功能
- Myeclipse 项目不显示svn信息 解决办法