开发者

Android ImageView not stretching vertically in ListView row

开发者 https://www.devze.com 2023-01-27 07:37 出处:网络
I have been struggling with this for several days now and I ran out of ideas. In my listview, each row can have a vertical bar flushed left with a different col开发者_如何学Goor depending on status.

I have been struggling with this for several days now and I ran out of ideas.

In my listview, each row can have a vertical bar flushed left with a different col开发者_如何学Goor depending on status. That "bar" has no other purpose than visual representation of status and is not clickable.

I implemented the vertical bar using an ImageView with background set to a drawable which has the desired color. The problem is that the vertical bar doesn't stretch, it's only 1 pixel high even though I specified fill_parent.

The row layout is like this:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/id1"
        android:scaleType="fitXY"
        android:layout_width="5dp"
        android:layout_height="fill_parent"
        android:background="@drawable/d1" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/id1">
...

(leaving content of the second relative layout out on purpose for simplicity)

My drawable d1 looks like this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/c1" />
    <corners android:topRightRadius="5dip" android:bottomLeftRadius="5dip" />
</shape>

So,

  1. Why isn't the ImageView stretching vertically?
  2. Is there a better way to implement this than using an ImageView? (I tried a simple View with a background color but it doesn't show up at all)

Any help greatly appreciated. Thanks


First off, you may as well be using a horizontal LinearLayout here instead of a RelativeLayout (since you only have two children anyways, you're not really saving any layout complexity the way you're using it).

Changing to a LinearLayout may fix this, but I suspect you may be running into a specific issue when it comes to matching heights on inflated RelativeLayouts as rows; see the comments on the answer to this SO question and this SO question.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号