【问题标题】:How to make ImageView fill vertically within RelativeLayout如何使 ImageView 在 RelativeLayout 中垂直填充
【发布时间】:2009-07-13 15:40:52
【问题描述】:

我将ImageViewTextView 放在用作列表项的RelativeLayout 中,并希望ImageView 随着TextView 的行号垂直增长。 ImageView 的drawable 是一个垂直条的png图片。

使用以下布局,认为它在 Eclipse 的布局视图中看起来不错,ImageView 在运行时不会填充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 布局视图中所示)

【问题讨论】:

  • 如果你使用android:background 而不是android:src 会改变什么吗?

标签: android eclipse android-imageview android-relativelayout


【解决方案1】:

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

<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. 通过将 TextView 与“drawableLeft”相结合来简化布局。
    2. 将图像制作成 9-patch 图像,使其相应增长。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多