2010-11-26 64 views
0

我一直在为此奋斗了好几天,而且我用尽了想法。Android ImageView不能在ListView行中垂直拉伸

在我的列表视图中,每行都可以有一个竖条,用不同的颜色刷新,具体取决于状态。该“酒吧”除了状态的视觉表示没有其他目的,并且不可点击。

我使用ImageView实现了垂直条,背景设置为具有所需颜色的drawable。问题是垂直条不伸展,即使我指定了fill_parent,它也只有1个像素高。

行布局是这样的:

<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"> 
... 

(第二相对布局的出来宗旨,为简单起见离开内容)

我绘制D1看起来是这样的:

<?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> 

所以,

  1. 为什么ImageView不能垂直拉伸?
  2. 有没有比使用ImageView更好的实现 的方法? (我试过 一个简单的查看与 背景颜色,但它并不显示 根本上)

任何帮助极大的赞赏。谢谢

回答

1

首先,您可以在这里使用水平的LinearLayout而不是RelativeLayout(因为您无论如何都只有两个孩子,您并不真正使用它来保存任何布局复杂性)。

更改为LinearLayout可能会解决此问题,但我怀疑当涉及将充气的RelativeLayouts上的高度与行匹配时,您可能会遇到特定的问题;请参阅对此SO questionthis SO question的回答的评论。

+0

我有一个相对布局,因为实际上有一个文本视图上方的对象,我省略xml保留这篇文章的简短。我从您给我的链接中阅读帖子,我已经在使用正确的方式来扩大视图。不过,我将尝试用多个LinearLayouts交换Relative布局以查看是否修复了它。 – 2010-11-26 23:19:56