首页 > 如何在单个碎片fragment中跳转替换整个布局?

如何在单个碎片fragment中跳转替换整个布局?

就是说,在mainContent中替换掉整个的mainLinearLayout,请问该怎么操作?我试了replace方法不行

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainLinearLayout"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <FrameLayout
        android:id="@+id/mainContent"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <android.support.v4.app.FragmentTabHost
        android:id="@+id/tabHost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <FrameLayout
            android:id="@+id/tabContent"
            android:layout_width="0dp"
            android:layout_height="0dp" />
    </android.support.v4.app.FragmentTabHost>


</LinearLayout>

replace只针对fragment来说,只会替换掉mainContent。mainLinearLayout属于activity,可以通过activity的setContentView来替换,但也就意味着fragment也会被替换掉。看你的layout,你的用意不就是想替换mainContent吗?没明白你要child去控制parent的意图。

【热门文章】
【热门文章】