当前位置:操作系统 > 安卓/Android >>

android中include标签的使用

在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include /> 标签来重用layout代码。
app_title.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/titleLayout" android:layout_width="fill_parent" android:layout_height="wrap_content"
                        android:background="@drawable/bt" xmlns:android="http://schemas.android.com/apk/res/android">
                       
                <TextView android:text="@string/login" android:id="@+id/title" android:textSize="20px" android:textColor="@color/white"
                        android:layout_width="wrap_content" android:layout_centerInParent="true" android:layout_height="wrap_content"/>               
                <Button android:text="返回" android:id="@+id/refresh" android:layout_width="wrap_content" android:layout_height="wrap_content"
                        android:layout_alignParentRight="true" android:focusable="false" android:textColor="@color/white"
                        android:background="@drawable/okbutton" android:layout_marginRight="3px"/>
</RelativeLayout>
app_tradelogin.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- android:layout_below与 android:layout_above 是必须设置的,否则界面不规则,不设置android:layout_above本界面没有滑动效果-->
<ScrollView android:layout_below="@+id/titleLayout" android:layout_above="@+id/appbottom" android:layout_width="fill_parent"
         android:layout_height="fill_parent" android:layout_centerInParent="true" xmlns:android="http://schemas.android.com/apk/res/android">
        <LinearLayout android:id="@+id/theWholeLinearLayout" android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:paddingLeft="10px" android:paddingTop="6px" android:paddingRight="10px" >
                <LinearLayout android:id="@+id/linearLayoutLeft" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content">
                        <TableLayout android:id="@+id/widget43" android:layout_width="fill_parent"
                                android:layout_height="fill_parent" android:orientation="vertical"
                                xmlns:android="http://schemas.android.com/apk/res/android" android:stretchColumns="1">
                                <TableRow >
                                <!--  引用定义好的TextView样式,如果这里的属性和样式里定义的属性重复,则这里会替换样式里定义的属性-->
                                        <TextView android:id="@+id/traderName" android:text="@string/traderName" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
                                        <Spinner android:id="@+id/traderNameS" android:layout_width="fill_parent" android:layout_height="wrap_content">
                                        </Spinner>
                                </TableRow>
                                       
                                <TableRow>
                                        <TextView android:id="@+id/departName" android:text="@string/departName" style="@style/StyleTextInfo1" mce_style="@style/StyleTextInfo1"/>
                                        <Spinner android:id="@+id/departNameS" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
                                </TableRow>
                              &nb

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,