gpt4 book ai didi

android - 如何通过宽度自动设置 View 的高度?

转载 作者:行者123 更新时间:2023-11-29 14:59:49 29 4
gpt4 key购买 nike

我有 FrameLayout: Width =match_parent,我想设置 Height = 70% * Width

例如:

 <FrameLayout
android:id="@+id/fiew"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp">

</FrameLayout>

如何设置Height =70% * Width

最佳答案

使用ConstraintLayout

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:background="@android:color/black"
app:layout_constraintDimensionRatio="H,3:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</FrameLayout>
</android.support.constraint.ConstraintLayout>

这里只是用app:layout_constraintDimensionRatio中的ratio来指定百分比

关于android - 如何通过宽度自动设置 View 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49555285/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com