Android ConstraintLayout 根据屏幕大小设置高度

时间:2021-04-19 11:54:49

标签: android xml android-layout android-constraintlayout

以下是我的 xml 布局。试图根据屏幕宽度设置 ConstraintLayout 的高度无法做到这一点,它不起作用。如何根据屏幕大小设置 ConstraintLayout 的高度。

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@color/accent_secondary"
app:cardBackgroundColor="@color/accent_secondary"
app:cardCornerRadius="10dp"
app:cardElevation="2dp"
app:cardUseCompatPadding="true">

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintDimensionRatio="1:0.35">



</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

0 个答案:

没有答案