代码之家  ›  专栏  ›  技术社区  ›  gaurav tiwari

用另一个childFragment替换childFragment将视图放在最上面

  •  0
  • gaurav tiwari  · 技术社区  · 7 年前

    我不知道我做错了什么。下面是包含父片段的xml文件。

      <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".ui.HomeActivity">
    
            <FrameLayout
                android:id="@+id/fragment_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="56dp"
                android:text="@string/title_mirror"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
    
    
            <android.support.design.widget.BottomNavigationView
                android:id="@+id/navigation"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="0dp"
                android:layout_marginEnd="0dp"
                android:background="?android:attr/windowBackground"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:itemIconTint="@drawable/bottom_nav_icon_color_selector"
                app:itemTextColor="@drawable/bottom_nav_icon_color_selector"
                app:menu="@menu/navigation" />
    
        </android.support.constraint.ConstraintLayout>
    
    Below is my parent fragment xml file containing child fragment:
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <com.smartmirror.emedsim.ui.mirror.DraggingPanel
            android:id="@+id/outer_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
    
            <LinearLayout
                android:id="@+id/main_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="true"
                android:orientation="vertical">
    
                <LinearLayout
                    android:id="@+id/queen_button"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_marginTop="10dp"
                    android:orientation="horizontal"
                    android:background="@color/transparent_black"
                    android:weightSum="3">
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/up_arrow"/>
                </LinearLayout>
    
                <FrameLayout
                    android:id="@+id/frame_video"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                </FrameLayout>
    
    
            </LinearLayout>
        </com.smartmirror.emedsim.ui.mirror.DraggingPanel>
    </RelativeLayout>
    

    下面是我从父片段添加子片段的文件:

     private void initViews(View view) {
            mDraggingPanel = view.findViewById(R.id.outer_layout);
            mMainLayout = view.findViewById(R.id.main_layout);
            Fragment childFragment = new DiscoveryFragment();
            FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
            transaction.replace(R.id.frame_video, childFragment).commit();
        }
    

    上面的第一个子片段添加成功。

    private void proceedFurther(int position, View v) {
            FragmentManager fragmentManager = ((AppCompatActivity) mContext).getSupportFragmentManager();
            FragmentTransaction transaction = fragmentManager.beginTransaction();
           Fragment childFragment = new VideoIntroScreen();
            childFragment.setArguments(args);
            transaction.replace(R.id.frame_video, childFragment);
            transaction.commit();
        }
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   gaurav tiwari    7 年前

    我设法找到了答案的答案。如果有人需要,我会回答的。

    我刚加了一句 在我的碎片布局文件和解决了我的视图重叠问题。

        2
  •  0
  •   Kevin Coppock    7 年前

    你需要确保你使用的是正确的 FragmentManager . 在你的 initViews() 方法,你用的是孩子 碎片管理器 父母的 Fragment. In the 继续() method, you're using the FragmentManager`(它承载父片段)。

    Activity
      -> Parent Fragment (in Activity FragmentManager)
         -> Child Fragment 1 (in Parent Fragment Child FragmentManager)
    

    碎片管理器