Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ImageView未在ListView行中垂直拉伸_Android - Fatal编程技术网

Android ImageView未在ListView行中垂直拉伸

Android ImageView未在ListView行中垂直拉伸,android,Android,我已经为此挣扎了好几天了,我的想法都没有了 在我的listview中,每一行都可以有一个竖条,根据状态的不同,用不同的颜色向左刷新。该“条”除了状态的视觉表示之外没有其他用途,并且不可点击 我使用ImageView实现了垂直条,背景设置为具有所需颜色的可绘制图形。问题是垂直条没有拉伸,它只有1像素高,即使我指定了fill\u parent 行布局如下所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/r

我已经为此挣扎了好几天了,我的想法都没有了

在我的listview中,每一行都可以有一个竖条,根据状态的不同,用不同的颜色向左刷新。该“条”除了状态的视觉表示之外没有其他用途,并且不可点击

我使用ImageView实现了垂直条,背景设置为具有所需颜色的可绘制图形。问题是垂直条没有拉伸,它只有1像素高,即使我指定了fill\u parent

行布局如下所示:

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

...
(为了简单起见,将第二个相对布局的内容保留在外)

我的可绘制d1如下所示:

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

所以

  • 为什么ImageView没有垂直拉伸
  • 有没有更好的实施方法 这比使用ImageView好吗?(一) 尝试了一个简单的视图 背景色,但不显示 (完全停止)

  • 非常感谢您的帮助。首先,您可以在这里使用水平线性布局,而不是相对线性布局(因为您只有两个孩子,所以使用它并没有真正节省任何布局复杂性)


    更改为线性布局可能会解决此问题,但我怀疑当涉及到以行形式匹配膨胀的相对长度上的高度时,您可能会遇到特定问题;请参阅对此问题的答案上的注释。

    我有一个相对的布局,因为在对象上方实际上有一个文本视图,我省略了该视图,以保持本文的xml简短。我从你给我的链接中阅读了帖子,我已经在使用正确的方法来扩大视图。不过,我将尝试用多个线性布局来交换相对布局,看看是否能解决这个问题。感谢Yoni为我指出那些有价值的SO线程。用线性布局替换根RelativeLayout修复了该问题。我不确定我是这个解决方案的忠实粉丝,因为这会使布局层次结构比需要的更复杂,但这可能是让它工作的唯一方法。虫子?