Fragment的转换

首先是xml的布局

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:id="@+id/show">

</LinearLayout>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/btnshow"
    android:layout_gravity="center"
    android:layout_marginTop="20dp"
    android:id="@+id/btnshow"
    android:onClick="onClick"/>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="100dp"
    android:orientation="vertical"
    android:id="@+id/txtshow2">
</LinearLayout>
View Code

第一个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.wdh.fragmentwork.FirstFragment">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="@string/tetshow1" />
View Code

第二个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.wdh.fragmentwork.ScondFragment">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="@string/txtshow2" />

</FrameLayout>
View Code

posted on 2017-04-18 16:03  王千小弟  阅读(118)  评论(0)    收藏  举报