1.利用Fragment完成布局。
①:建立TOP Fragment
布局:
②:建立Left Fragment<FrameLayout 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" tools:context="com.example.administrator.jreduch06.fragment.MainFragment"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:textSize="30sp" android:text="MainFragment" android:background="#19e6d4" android:textColor="#ffffff" /> </FrameLayout>
<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"
android:background="#bece0d"
tools:context="com.example.administrator.jreduch06.fragment.LeftFragment">
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="#dfdc24"
android:gravity="center"
android:textSize="30sp"
android:textColor="#ffffff"
android:text="LeftFragment" />
</LinearLayout>
③:建立MainFragment
④:建立整体布局,将其放到一起。<FrameLayout 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" tools:context="com.example.administrator.jreduch06.fragment.MainFragment"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:textSize="30sp" android:text="MainFragment" android:background="#19e6d4" android:textColor="#ffffff" /> </FrameLayout>
<?xml version="1.0" encoding="utf-8"?> <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" tools:context=".Fragment1Activity"> <fragment android:layout_width="match_parent" android:layout_height="100dp" android:name="com.example.administrator.jreduch06.fragment.TopFragment" android:id="@+id/top_fragment" android:layout_alignParentTop="true" android:layout_alignParentEnd="true"> </fragment> <fragment android:layout_width="match_parent" android:layout_height="300dp" android:id="@+id/leftfragment" android:name="com.example.administrator.jreduch06.fragment.LeftFragment" android:layout_below="@+id/top_fragment" android:layout_alignParentStart="true"> </fragment> <fragment android:layout_width="400dp" android:layout_height="match_parent" android:id="@+id/mainfragment" android:name="com.example.administrator.jreduch06.fragment.MainFragment" android:layout_below="@+id/leftfragment" android:layout_alignParentStart="true"> </fragment> </RelativeLayout>
效果: