我有一個應用程序,我交換了兩個碎片。這些片段位於LinearLayout中。在linearlayout下面,我有圖標(ImageViews),當點擊時隱藏或顯示適當的片段。當應用第一次加載時,一切都很好。在我退出我的應用程序並使用其他應用程序後,返回到我的應用程序片段不會隱藏/顯示當我單擊圖標(ImageView)。這是怎麼回事?它與活動生命週期有關嗎?Android碎片不能隱藏
xml_layout:
<LinearLayout
android:id="@+id/Linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</LinearLayout>
onCreate()
{
ft = this.getSupportFragmentManager()
.beginTransaction();
frag1= new Frag1();
frag2= new Frag2();
ft.add(R.id.linearlayout,frag1);
ft.add(R.id.linearlayout, frag2);
ft.hide(frag1).show(frag2);
ft.commit();
icon1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ftt = MainActivity.this.getSupportFragmentManager()
.beginTransaction();
ftt.hide(frag2).show(frag1);
ftt.commit();
}
});
}
顯示圖片代碼點擊 – vinitius 2015-02-11 21:50:35
@ vinitius我已發佈它 – 2015-02-11 21:54:20