簡體   English   中英

Android片段無法正常替換

[英]Android Fragment Not Replacing Properly

我正在嘗試使用片段構建3.0的應用程序。 在應用程序的左側有一個靜態片段,在右側有一個動態片段。 動態部分中的每個片段都有一個標題。 每當我去替換初始片段時,第一個的標題仍然顯示在第一個標題的上方。 連續替換替換下部但仍然顯示初始標題(抱歉,我還不能發布圖像)。

我能做的最好的形象:

初始標題

新標題

內容(顯示正常)

main.xml中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <fragment
        android:id="@+id/static_fragment"
        android:name="ruleout.android.History_Fragment"
        android:layout_width="500dp"
        android:layout_height="match_parent" />
    <fragment
        android:id="@+id/dynamic_fragment"
        android:name="ruleout.android.New_Screen_Fragment"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" />
</LinearLayout>

部分MainActivity用於更改片段

private void open(Fragment toShow)
{
    FragmentTransaction fragmentTransaction = FragMag.beginTransaction();
    fragmentTransaction.replace(R.id.dynamic_fragment, toShow);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

如果您需要任何其他信息,請告知我們,並提前感謝您的幫助。

如果要動態更改片段,則無法在布局中聲明它們。 Fragment文檔中有一個示例,它正在執行我認為您正在描述的內容,其中布局中包含一個靜態片段以及一個FrameLayout,用於保存將動態添加和替換的Fragment。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM