【问题标题】:Android ConstraintLayout constraintHeight_percent not of screenAndroid ConstraintLayout constraintHeight_percent 不属于屏幕
【发布时间】:2018-09-30 14:54:36
【问题描述】:

下面的 XML 说高度应该是整个 ConstraintLayout 高度的 6%,而不是父视图的高度。这个特殊的ConstraintLayoutScrollView 中大约有 2.5 个屏幕高

如何使高度为屏幕高度的 6%?

<TextView
    android:id="@+id/udpate_profile"
    app:layout_constraintTop_toBottomOf="@+id/boardgames"
    android:layout_marginTop="50dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_width="0dp"
    app:layout_constraintHeight_percent="0.06"
    android:layout_height="0dp"
    android:text="@string/update_profile"
    android:tag="update"
    android:gravity="center"
    android:textSize="18sp"
    android:textColor="@color/white_color"
    android:background="@color/orange_color"
    android:lines="1"
    />

【问题讨论】:

  • 您可以在约束布局中使用水平线。有关约束布局指南的更多信息,请查看here
  • 你是对的,当然,我经常使用它们。不幸的是,指南也有同样的问题。如果我将指导线设置为 94%,它将是 ConstraintLayout 的 94%,即 ScrollView 中大约 2.5 个屏幕高度。我的目标是让这个特定的 textView 为 screenHeight 的 6%。你的答案没有达到目标。
  • 您能否将您的整个 xml 代码放入您的问题中。而且您的屏幕截图也没有显示问题。所以,让它正确。
  • 对不起。我已经继续前进,必须对布局进行大量修改才能解决问题。底线是 6% 的高度,或某个百分比的指南,都与约束布局的高度有关。在 ScrollView 中,如果能以某种方式引用屏幕或父级 (ScrollView) 的高度,那就太好了。

标签: android android-constraintlayout


【解决方案1】:

对于可能面临同样问题的其他人,如this answer 中所述,最好的方法是使用app:layout_constraintDimensionRatio

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2021-01-23
    • 1970-01-01
    相关资源
    最近更新 更多