安卓ImageView缩放以适应另一个视图

4
我有一个相对布局,其中包括一个TextView和一个ImageView:
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"/>
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:adjustViewBounds="true"/>
</RelativeLayout>

它看起来如下:

enter image description here

我想要实现的是:

enter image description here

这意味着我希望我的ImageView按高度缩放以适应TextView。是否可以在xml中完成,而不需要使用Java编码? 如果我能写出类似于以下内容的东西

android:layout_height="match_that_TextView"

这可以解决这个问题,但我猜想这是不可能的。

1个回答

1

在RelativeLayout中设置固定高度


我不想使用神奇数字。我希望ImageView的高度取决于TextView的高度。 - Nick
然后只需以编程方式获取TextView的大小并设置ImageView的高度。 - imperator_sp

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接