include的使用

String.xml文件下设置<String></String>的值如下:

<string name="text">include的使用</string>    <!-- 在activity_main.xml中使用 -->
<string name="bottom">版权所有,copy 1999-2013 德升时装公司</string>  <!-- 在bottom.xml中使用 -->

bottom.xml中的代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bottom"
android:textSize="15sp"/>
</LinearLayout>

activity_main.xml的代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/text" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#cccccc"
android:orientation="vertical"
>

<include layout="@layout/bottom" android:id="@+id/borrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

</RelativeLayout>

  注:include的使用是为了去优化原始的布局代码,所以在学校include之前先把布局学好

posted @ 2016-03-14 09:03  计应143涂海林  阅读(161)  评论(0编辑  收藏  举报