Android片段中的问题:仍然点击上一个片段

16 android android-fragments android-fragmentactivity

我已经开发了一个应用程序,它有导航抽屉和抽屉内的许多片段,所以当我在片段中打开片段时我遇到问题,在一个片段中我有列表视图当用户点击listview项目时他们获得与列表项相关的数据所以我面临问题它仍然点击不可见的列表但单击

Fragment的布局

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutDrawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:clickable="true"
        android:background="@drawable/backgroung"
        android:id="@+id/content_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"></FrameLayout>

    <LinearLayout
        android:id="@+id/linearDrawer"
        android:layout_width="@dimen/dp260"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/white"
        android:layout_gravity="start">

        <RelativeLayout
            android:id="@+id/userDrawer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:layout_margin="@dimen/dp10">
Run Code Online (Sandbox Code Playgroud)

开放片段的代码

Fragment fragment = new FragmentContactDetails();
            FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
            transaction.add(((ViewGroup) getView().getParent()).getId(), fragment);
            transaction.addToBackStack(null);
            transaction.commit();

            Bundle args = new Bundle();
            int index = adapter.arrayList.indexOf(adapter.propertyList.get(position));

            args.putInt(Constant.POSITION, index);
            Toast.makeText(getActivity(), "" + index + "----" + adapter.propertyList.get(position).getName(), Toast.LENGTH_LONG).show();
            fragment.setArguments(args);
Run Code Online (Sandbox Code Playgroud)

Emi*_*Adz 59

看看我的这个问题:

点击片段后面的隐形布局:

在这种情况下帮助我的原因和接受的答案是添加

android:clickable="true"

属性到ViewGroup您为顶部片段设计的布局的顶层(要点击的片段).这样顶部片段就会拦截您的点击,无论它们发生在何处(即使没有对其应用任何操作)也不会传递给较低级别​​的片段/活动布局.