gpt4 book ai didi

android - 在 FrameLayout 中拉伸(stretch)图像以匹配相邻元素的高度?

转载 作者:行者123 更新时间:2023-12-05 00:17:46 26 4
gpt4 key购买 nike

RelativeLayout 中高度设置为 fill_parent 的 ImageView 实例将像relativelayout 一样拉伸(stretch)。例如。如果相同布局中的 EditText 高度为 10 行,则图像将拉伸(stretch)到 10 行高。

如何在 FrameLayout 中复制此行为?无论 FrameLayout 中其他项目的高度如何,设置为 fill_parent 的图像高度似乎与 wrap_content 的行为相同。

我更愿意纯粹在 XML 中处理这个问题。

最佳答案

我找到了一个(可能是黑客)解决方法 - 将 FrameLayout 包装在 LinearLayout 中,让我将 FrameLayout 设置为 fill_parent ,这样它的子级就可以相应地拉伸(stretch)。所以:

<LinearLayout
orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<FrameLayout
android:measureAllChildren="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:src="@drawable/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:layout_gravity="right|center_vertical" />
</FrameLayout>
</LinearLayout>
<RelativeLayout ... >
... other stuff ...
</RelativeLayout>
</LinearLayout>

ImageView 将拉伸(stretch)到 EditText 的高度。

关于android - 在 FrameLayout 中拉伸(stretch)图像以匹配相邻元素的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5733830/

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