【问题标题】:Set Minimum Percent Height for Layout inside Constraint Layout为约束布局内的布局设置最小百分比高度
【发布时间】:2021-10-30 21:27:45
【问题描述】:

我有一个ConstraintLayout,其中有一个ViewCardView。 CardView 是总布局的75%25% 是其他视图。 CardView 包含一些在普通屏幕上看起来不错的视图。当字体大小增加时,会看到 CardView 内的视图重叠。我们如何通过在% 中为 ConstraintLayout 中的视图设置最小高度来实现这一点。因此,如果内部视图有重叠,视图高度将被推高,保持最小 75%。

【问题讨论】:

  • 你能把你的布局代码吗?

标签: android view android-constraintlayout android-cardview


【解决方案1】:

您只能同时使用一个 app:layout_constraintHeight_minapp:layout_constraintGuide_percent。如果您想将两者结合起来,您可以在 onCreate 方法中手动设置 CardView 的高度。

constraintLayout.post {
    cardView.minimumHeight = (constraintLayout.height * 0.75).toInt()
}

【讨论】:

  • 在 ConstraintLayout 上找不到 post 方法
  • post 方法属于 View,因此您可以在任何 View 中调用该方法,包括 ConstraintLayout。
  • 但是,我用 Kotlin 编写代码。如果你使用Java,代码可能会稍作改动。
猜你喜欢
  • 2021-02-27
  • 1970-01-01
  • 2021-08-12
  • 2011-09-06
  • 1970-01-01
  • 2018-06-01
  • 2021-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多