Android中文API-Include标签
2016-04-25 15:08
465 查看
虽然,Android提供了多种多样的可重用轻量级的交互元素(如:TextView 等控件),但是你可能也想重用一些相对较大的特殊布局xml。为了有效的重用布局文件,你可以使用include标签和merge标签,是特殊的布局文件嵌入当前的布局。
可重用的布局是特别强大的。例如一个包含确定和取消的button面板,或者伴随着文案的自定义进度条(progressbar )。这就意味了一款应用中,复杂布局中共同的部分都可以被提取出来,独立管理,然后以include的方式,嵌入需要它的地方。所以,你也可以通过自定义View的方式创建一个独立的UI组件,这样使用起来,比通过include的方式更加简单。
Create a Re-usable Layout
创建一个可重用的布局文件。(
titlebar.xml)
<FrameLayout
xmlns: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:
<LinearLayout
xmlns: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_heightand
android:layout_width
这两个属性,才能让它生效。
作者有话说:如果您需要Android中文API,请扫一扫下面的二维码,您的关注,就是我的动力。
相关文章推荐
- android /Cordova LOG 、console 调试调试打印log
- 【Android】获取手机中已安装apk文件信息(PackageInfo、ResolveInfo)(应用图片、应用名、包名等)
- 关于Activity生命周期的理解 一(直白高效版)
- Android studio 使用技巧以及常用设置
- android自定义view----等分饼图,实现每个块中间的间隔
- Android关于OnTouch 和OnClick同时调用冲突的解决方案
- Android继承现有控件拓展实现自定义控件textView
- Android开发内存泄露之--Handler引起的内存泄露
- Android proguard遇到的若干问题以及解决思路
- ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsLis
- Android POI 百度地图——周边检索
- Android studio Error:Plugin with id 'com.github.dcendents.android-maven' not found
- Android如何保证数据加载下一页确定当前listview的位置
- Android-Charts,Android图形图表控件
- Android保存ArrayList至SharedPreferences
- Android之玩转MPAndroidChart让(折线图、柱形图、饼状图、散列图、雷达图)优雅的舞动
- Android Scroll滑动效果实例
- 实用Jacoco代码覆盖率Android集成与使用
- Cordova6.1、ionic、android交互自定义插件
- Android启动过程深入解析