【发布时间】:2019-07-08 07:16:08
【问题描述】:
我的问题与这个有关:
Multiple Fragments in One Activity
我在平板电脑上的一个活动中显示三个片段:两个只包含文本(成分和步骤),一个是 Exoplayer 和文本。所有片段都包含在各自的框架布局中。我使用约束布局作为父布局。由于成分片段中文本的长度,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>
【问题讨论】:
-
为每个框架布局添加适当的约束。我看到你错过了 video_fragment_container 等的结束约束。除非为每个孩子设置了所有四个(开始、结束、顶部、底部)约束,否则约束布局将无法正常工作。
标签: android android-fragments android-linearlayout android-constraintlayout android-layout-weight