【问题标题】:Android fragment overlap another fragmentAndroid片段重叠另一个片段
【发布时间】:2015-09-01 11:25:12
【问题描述】:

首先我打开了从相机拍摄图像的片段,然后在另一个片段上显示图像。

但是当我通过添加再次打开新片段然后它显示第一个片段并添加新片段时我的问题

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/searchuserLayout"
    android:background="@color/white"
       android:clickable="true">
<RelativeLayout 
    android:id="@+id/backButtonRL"
    android:layout_width="fill_parent"
    android:layout_height="30dp"
    android:layout_alignParentTop="true"
   android:background="@color/action_bar">
      <TextView
        android:id="@+id/backTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:gravity="left"
        android:layout_marginLeft="10dp"
        android:text="@string/selfie.cancel"
        android:textColor="@color/white" />
       <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:gravity="left"
        android:textStyle="bold"
        android:text="@string/searchFragment_usersearch"
        android:textColor="@color/black" />
        <TextView
        android:id="@+id/done"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:gravity="left"
        android:layout_marginRight="10dp"
        android:text="@string/done"
        android:textColor="@color/white" />

   </RelativeLayout>
    <customview.ScrollDetectableListView
        android:id="@+id/searchlistView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/backButtonRL"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center_horizontal"
         android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="5dp"
        android:divider="@color/white"
        android:dividerHeight="1sp"/>
</RelativeLayout>

【问题讨论】:

    标签: android


    【解决方案1】:

    有时,当我们尝试使用不同类型的片段时,会出现片段重叠问题(即在少数片段中使用支持片段,在其他片段中使用普通片段)。

    还可以尝试为 XML 文件中的片段设置背景颜色。

    【讨论】:

      【解决方案2】:

      如果您在事务期间使用addFragment(); 而不是replaceFragment();,则会发生这种情况。这是因为新片段将添加到旧片段之上(旧片段保持原样)。

      因此,为避免这种情况,您可以在 Fragment 的视图(布局)中添加 Background(颜色或图像)。这将阻止下面片段的可见性。

      您也可以查看THIS ANSWER 以供参考。

      【讨论】:

      • 我也添加了背景颜色,但它显示了两个片段
      • 能否请您发布两个片段的xml,您也可以使用替换而不是添加。
      • SearchUserPollTimeFragment fragment2 = new SearchUserPollTimeFragment(); FragmentManager fragmentManager = getFragmentManager(); Fragment currentFragment = fragmentManager.findFragmentById(R.id.frame_container); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.hide(currentFragment); fragmentTransaction.setCustomAnimations(R.anim.fadein_anim, R.anim.fadeout_anim,R.anim.fadein_anim, R.anim.fadeout_anim); fragmentTransaction.add(R.id.frame_container,fragment2); fragmentTransaction.commit();
      • 我正在隐藏当前片段并添加新片段
      • 请发布片段的 xml。
      猜你喜欢
      • 2013-06-30
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多