代码之家  ›  专栏  ›  技术社区  ›  an0

如何使ImageView在RelativeLayout内垂直填充

  •  4
  • an0  · 技术社区  · 17 年前

    我放了一个 ImageView TextView 在一段时间内 RelativeLayout 作为列表项使用,并希望 随着行数垂直增长 文本框 .可抽出的 图片框 是一个 巴布亚新几内亚

    对于以下布局,虽然在Eclipse的布局视图中看起来不错,但是 图片框 不填充的高度 RelativeView 在运行时。相反,它始终保持原始图片的高度。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent" >
       <ImageView android:id="@+id/iv"
           android:layout_width="wrap_content"
           android:layout_height="fill_parent"
           android:layout_alignParentLeft="true"
           android:src="@drawable/vbar"
           android:adjustViewBounds="false"
           android:scaleType="fitXY"/>
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:singleLine="false"
           android:layout_toRightOf="@id/iv"
           android:layout_alignParentBottom="true" />
    </RelativeLayout>
    

    (或如Eclipse布局视图所示) ?

    2 回复  |  直到 10 年前
        1
  •  1
  •   MysticMagicÏ¡    13 年前

    我对你的代码做了一些更改。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <TextView
            android:id="@+id/tv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:singleLine="false"
            android:text="@string/text" />
    
        <ImageView
            android:id="@+id/iv"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_above="@id/tv"
            android:adjustViewBounds="false"
            android:scaleType="fitXY" />
    
    </RelativeLayout>
    

    现在它给出了适当的输出。 我所做的是,首先声明textview并将其与父视图底部对齐。然后声明imageview并将其放在textview的顶部。因此,imageview将从textview的正上方开始,并获取所有剩余高度。我也测试了多行文本视图。希望能有帮助。

        2
  •  -1
  •   Bill Mote    13 年前

    我会做几件事:

    1. 通过将TextView与“drawableLeft”组合,简化布局。
    2. 将图像设置为9面片图像,使其相应增长。