1.首先自定义一个具备某项特殊功能的布局,如,title.xml布局
该布局是用来放在某布局的上方,进行返回,编辑等操作。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"<!--要选择wrap_content,否则会充斥整个界面--> android:background="@drawable/title" android:orientation="horizontal"> <Button android:id="@+id/back" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:layout_margin="5dip" android:background="@drawable/back" android:text="back" android:textColor="#fff" android:textSize="24sp" /> <TextView android:id="@+id/tittle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="this is a tittle" android:textSize="24sp" android:textColor="#fff" /> <Button android:id="@+id/edit" android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:layout_margin="5dip" android:background="@drawable/edit" android:text="edit" android:textColor="#fff" android:textSize="24sp" /> /> </LinearLayout>2在first_layout.xml中利用<include>标签引入title.xml布局,显示在上方。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/tittle"/> </LinearLayout>