如何在一个活动中显示多个片段?

问题描述 投票:0回答:1

我的问题与此有关:

Multiple Fragments in One Activity

我在平板电脑上的活动中显示三个片段:两个仅包含文本(成分和步骤),一个包含Exoplayer和文本。所有片段都包含在相应的帧布局中。我使用Constraint Layout作为父布局。由于成分片段中文本的长度,ExoPlayer在纵向和横向模式下均未均匀显示。它应该始终位于该片段的右侧,并且位于Steps Fragment之上。另外两个片段在屏幕左侧正确显示。

我考虑过使用线性布局和设置布局权重,但后来读了几篇不推荐的帖子。在这种类型的布局中显示ExoPlayer片段的最佳方法是什么?先感谢您。

<?xml version="1.0" encoding="utf-8"?>

<ScrollView 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/scroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tablet_detail_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context="annin.my.android.bakingapp.ui.IngredientStepsActivity">
        <!--
        This layout is a two-pane layout for the master/detail flow.
        -->
    <FrameLayout
            android:id="@+id/ingredients_fragment_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/steps_fragment_container"
            app:layout_constraintVertical_weight="0.4"
            >

        </FrameLayout>

        <FrameLayout
            android:id="@+id/video_fragment_container"
            android:layout_width="wrap_content"
            android:layout_height="250dp"
            android:layout_marginStart="5dp"
            android:layout_marginTop="80dp"
            android:layout_marginEnd="60dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@+id/ingredients_fragment_container"
            app:layout_constraintVertical_weight="0.4" >

        </FrameLayout>

        <FrameLayout
            android:id="@+id/steps_fragment_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="40dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/ingredients_fragment_container"
            app:layout_constraintVertical_weight="0.4"
           >

        </FrameLayout>
    </android.support.constraint.ConstraintLayout>
</ScrollView>
android android-fragments android-linearlayout android-constraintlayout android-layout-weight
1个回答
0
投票

它非常简单,只需制作2个片段,然后为它们分配相应的片段文件,如下所示:

<fragment
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/my_fragment"
    android:name="annin.my.android.bakingapp.ui.Fragment1" />

<fragment
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/my_fragment_2"
    android:name="annin.my.android.bakingapp.ui.Fragment2" />
© www.soinside.com 2019 - 2024. All rights reserved.