我正在使用嵌套片段,并通过代码从一个片段传递到另一个片段。
但是当我使用嵌套布局时,就不会发生这种情况。
有人知道为什么会发生这种情况吗?
ImageView search = (ImageView) root.findViewById(R.id.search);
search.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.addToBackStack(null);
transaction.replace(R.id.parent, ChildFragment.newInstance());
transaction.commit();
}
});
然而,有时候在子片段中即使父片段中的项目不可见(被子片段覆盖),我仍然可以点击它们。特别是当子片段具有简单布局类型时会发生这种情况。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFF0D1"
android:id="@+id/child">
...some stuff...
</RelativeLayout>
但是当我使用嵌套布局时,就不会发生这种情况。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFF0D1"
android:id="@+id/child">
<ScrollView
android:id="@+id/scr"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:padding="10dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
...same stuff...
</RelativeLayout>
</ScrollView>
</RelativeLayout>
有人知道为什么会发生这种情况吗?