与ConstraintLayout中的片段一起使用时,Textview不可见

时间:2018-03-25 18:32:44

标签: android android-fragments youtube youtube-data-api android-constraintlayout

我使用YouTubePlayerFragment作为片段,上面是textview。不知何故,标题被隐藏,渲染时只有空格。很明显,TextView存在于那里,但它没有显示出来。当我将可见性设置为不可见时,我得到同样的效果。

现在:

enter image description here

目的:

enter image description here

查看此视图​​的XML:

    X = diabetes_normalized['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age']

在主要活动中,我使用此布局包含标签,并在按钮点击时更改其可见性。

1 个答案:

答案 0 :(得分:0)

片段在约束布局中是臭名昭着的。将Fragment放在FrameLayout内,并将约束放在其中。此外,我建议给FrameLayout一个固定的高度或使用height="0dp"的比率。

<FrameLayout
        android:id="@+id/frameContainer"
        android:layout_width="0dp"
        android:layout_height="120dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tv_title">
        <fragment
                android:id="@+id/youtubeFragment"
                android:name="com.google.android.youtube.player.YouTubePlayerFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
</FrameLayout>

快乐编码:D