android - 如何使用约束布局设置recyclerview最小高度wrap_content但最大百分比?

标签 android android-layout android-recyclerview android-constraintlayout

我有一个 recyclerview,我正在使用约束布局。现在我想用高度作为包装内容 但想以百分比设置最大高度。我如何使用约束布局来实现这一点?

   <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:visibility="gone"

    app:layout_constraintTop_toBottomOf="@+id/search_view"

    android:layout_height="0dp"
    app:layout_constraintHeight_default="wrap"
    app:layout_constraintHeight_max="500dp"
    android:scrollbars="vertical"/>

最佳答案

由于您使用的是 ConstraintLayout你可以使用 Guideline如下约束 RecyclerView's高度。

<androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.85"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:scrollbars="vertical"
        app:layout_constraintTop_toBottomOf="@+id/search_view"
        app:layout_constraintBottom_toBottomOf="@id/guideline3" />
Guideline有一个 layout_constraintGuide_percent您可以在其中为 RecyclerView 指定所需的百分比.

关于android - 如何使用约束布局设置recyclerview最小高度wrap_content但最大百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64857667/

相关文章:

android - 使用 DialogFragment 和导航库时将对话框显示为全屏或对话框

java - Android开发中JNi中如何将jchar转换为char?

android - 为什么 wrap_content 是填充高度?

android - 对话框 fragment 和 RecyclerView

Android recyclerView,如何指定行布局

安卓垂直微光

android - 创建接受 xml 属性中其他布局的自定义 View

java - Android Design Navigation Drawer - 如何在导航 xml 中添加开关?

android - 如何检测 recyclerview 的滚动超出范围?

Android - Google SignInButton 文本未居中