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

2024-04-29

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

片段的布局

 <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">

打开Fragment的代码

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);

看看我的这个问题:

片段后面的不可见布局被点击: https://stackoverflow.com/questions/21141855/an-invisible-layout-behind-the-fragment-is-getting-clicked

在这种情况下对我有帮助的以及接受的答案指出的是添加

android:clickable="true"

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Fragment 中的问题:仍然单击上一个片段 的相关文章

随机推荐