Android ListView中如何在ImageView的右侧插入大小不同的图像而不改变图像大小

3
我想要一个ImageView(大小为50dp / 50dp),并希望在这个图像的右边有一个ListView(其大小取决于我的数据库,但这不是重点)。 图像应保持其大小,而列表应具有自己的大小。
我的问题是:我的ListView使用左侧ImageView的高度。 我希望我的List可见,没有任何滚动条。所有这些代码都放置在RelativeLayout中。
<LinearLayout
        android:id="@+id/listAddresses"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_below="@id/AnotherImageWithListOnItsRight" >
        <RelativeLayout
            android:id="@+id/iconAddress"
            android:layout_width="50dp"
            android:layout_height="fill_parent" >
            <ImageView
                android:layout_height="50dp"
                android:layout_width="50dp"
                android:src="@drawable/orange_message" android:scaleType="fitXY"
                />
        </RelativeLayout>
        <ListView 
            android:layout_toRightOf="@id/iconAddress"
            android:id="@+id/listAddressTrue" 
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:divider="#FFCC00"
            android:dividerHeight="4px" >      
        </ListView>
</LinearLayout>

我设法让我的ListView没有滚动条,但是如果我这样做,我的图片的高度就非常糟糕...所以我想我可以制作一个RelativeLayout,专门用于我的图片,这样我的图片就不会被重新调整大小,但它没有起作用。
能否有人帮助我?
注:对我的英文表示抱歉。

看不到问题。我复制了你的xml,左侧得到一个50dp x 50dp的iv,右侧是一个向下延伸到底部的listview,这似乎是你想要的? - NameSpace
请尝试这个。将RelativeLayout的高度android:layout_height="fill_parent"更改为android:layout_height="wrap_content"。 - ASP
我使用了wrap_content但是没有起作用。 - Sideness
它和你一起工作了吗?嗯...这有点尴尬! - Sideness
你能否澄清一下当你说你得到了一个调整大小的图像时出现的错误。你的图像是否延伸到屏幕底部?还是只有50x50dp导致图像变形,但不会延伸到屏幕长度? - NameSpace
通过我在问题中提供的代码,我有一个50 dp / 50 dp的图像和一个具有相同高度的列表视图(我必须在这个小的50dp高度中滚动才能看到列表的其余部分)。但是经过尝试了很多方法后,我成功地获得了完整的列表而没有任何滚动。左侧图像的宽度还可以,但是图像的高度非常大(与列表相同),因此图像非常糟糕。 - Sideness
2个回答

2

这里:

<ListView 
        android:layout_toRightOf="@id/iconAddress"

您正在尝试使用layout_toRightOf属性,但这仅在您位于RelativeLayout内部时才起作用,但是您的ListView位于LinearLayout内部

因此,也许将LinearLayout更改为RelativeLayout对您有用,因为那样您实际上可以使用这个属性


好的,我已经用相对布局替换了它。 但是我仍然有一个滚动条而不是完整的列表... - Sideness
LinearLayout 的默认方向是水平的,这就是为什么我不明白这个修复如何改变结果。 - NameSpace
我的回答解释了为什么layout_toRightOf属性不能工作:因为它是无效的属性,在LinearLayout中不能使用,参见这个问题的答案:http://stackoverflow.com/questions/12722246/android-layout-torightof-and-androidlayout-below => 所以将LinearLayout更改为RelativeLayout对我来说听起来不是一个坏主意。 - donfuxx

2

试试这个...

<LinearLayout
        android:id="@+id/listAddresses"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:layout_below="@id/AnotherImageWithListOnItsRight" >
            <ImageView
                android:layout_height="50dp"
                android:layout_width="50dp"
                android:src="@drawable/orange_message" android:scaleType="fitXY"
                />
        <ListView 
            android:id="@+id/listAddressTrue" 
            android:layout_height="fill_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:divider="#FFCC00"
            android:dividerHeight="4px" >      
        </ListView>
</LinearLayout>

好的,我尝试了你给我的内容。 现在,ListView是空的(我认为这是由于0 dp的宽度)。 但是,列表的高度更大,图像的大小也不错!(但是列表是空的...) - Sideness
@user3340507 你在你的listview中添加了 android:layout_weight="1" 吗? - Hariharan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接