我有一個活動A與裏面的片段A.Android片段重疊以前的視圖和按鈕監聽器
活性A使用佈局X,和片段A使用佈局A.
代碼佈局X的:
<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=".MainActivity" >
<fragment
android:id="@+id/fragment1"
android:name="android.app.DialogFragment"
android:layout_width="wrap_content"
android:layout_height="500dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="113dp"
class="com.example.fragtester.FragA" />
</RelativeLayout>
佈局A是僅有的TextView +的LinearLayout。
我設置使用佈局B.
現在,我使用以下代碼中活性的改變片段另一片段B:
Fragment f = new FragB();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment1, f);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
我最終佈局乙下佈局顯示A.
所以我使用的FrameLayout包裹的片段佈局X和使用
ft.replace(R.id.FrameLayout1, f);
現在視圖很好地工作。雖然,另一個問題出現了。
儘管佈局B覆蓋佈局A,但按鈕仍處於活動狀態。
這意味着當我查看佈局B時,即使我沒有看到它,我仍然可以單擊佈局A上的按鈕。
甚至當我添加碎片C/D/E .....(佈局C/D/E ....)時,佈局A上的按鈕仍處於活動狀態。
任何人都可以解釋爲什麼是這樣嗎?我是否錯誤地使用了片段?謝謝!
一種通過的方法是使佈局A空白,並使用其他佈局來覆蓋它。但它似乎並不是「正確」的方式?
請問您能解釋一下爲什麼是這樣嗎?謝謝!! – 2013-03-13 08:06:22