gpt4 book ai didi

android - 使用 PercentRelativeLayout 仅指定宽度(高度自动)

转载 作者:行者123 更新时间:2023-11-29 01:12:10 24 4
gpt4 key购买 nike

可以使用 PercentRelativeLayout 仅指定所需的宽度尺寸并获得自动高度吗?

我的意思是这样做:

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/earthImageView"
app:layout_widthPercent="30%"
android:src="@drawable/earth"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"/>
</android.support.percent.PercentRelativeLayout >

View 具有正确的宽度,但如果我检查布局边界,我可以看到高度为 MATCH_PARENT。这意味着帽子 android:adjustViewBounds="true"不工作。

我尝试添加 app:layout_widthPercent="WRAP_CONTENT"但没有效果。

编辑

在做相反的情况时也有问题:

<ImageView
android:id="@+id/earthImageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_heightPercent="20%"
android:src="@drawable/earth"
android:adjustViewBounds="true"/>

最佳答案

如果我理解正确,您想指定宽度并将高度自动设置为 adjustViewBounds 给您的值。

如果是这样的话,下面应该做你想做的(我已经将布局和 imageView 高度都设置为 wrap_content):

<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/earthImageView"
android:layout_height="wrap_content"
app:layout_widthPercent="30%"
android:src="@drawable/lapin"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"/>
</android.support.percent.PercentRelativeLayout >

关于android - 使用 PercentRelativeLayout 仅指定宽度(高度自动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42211489/

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