【问题标题】:Android ListView toRightOf ImageView with different size without resizing imageAndroid ListView toRightOf ImageView 具有不同大小而无需调整图像大小
【发布时间】:2014-03-24 02:51:11
【问题描述】:

我想要一个 Imageview(大小 50dp / 50 dp),在这个图像的右侧,我想要一个 ListView(它的大小可变,取决于我的数据库,但这不是重点) . Image 应该保持它的大小,而 List 应该有它自己的大小。

我的问题是:我的 ListView 采用左侧 Imageview 的高度。我希望我的列表可见,没有任何滚动。 所有这些代码都放在一个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,专用于我的图像,所以我的图像不会调整大小,但它不起作用。

谁能帮帮我?

PS: 对不起我的英语..

【问题讨论】:

  • 没有发现问题。我复制了你的 xml,左边有一个 50dp x 50dp iv,右边有一个延伸到底部的列表视图,这似乎是你想要的?
  • 请试试这个。将 RelativeLayout android:layout_height="fill_parent" 的高度更改为 android:layout_height="wrap_content"
  • 我放了 wrap_content 但它没有用..
  • 它对你有用吗?嗯……这太尴尬了!
  • 当你说你得到一个调整大小的图像时,你能澄清你的错误吗?您的图像是否延伸到屏幕底部?还是只是 50 x 50 dp 导致图像变形,但没有延长屏幕长度?

标签: android listview imageview height size


【解决方案1】:

这里:

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

您正在尝试使用layout_toRightOf 属性,但这仅在您位于RelativeLayout 内时有效,但您的ListView 位于LinearLayout

所以也许将LinearLayout 更改为RelativeLayout 对你有用,因为这样你就可以实际使用这个属性了

【讨论】:

  • 好的,我用Relativelayout替换了。我仍然有一个滚动条而不是完整列表...
  • LinearLayout 的默认方向是水平的,这就是为什么我看不到这个修复如何改变结果。
  • 我的回答解释了为什么 layout_toRightOf 属性不能工作:因为它是在 LinearLayout 中使用的无效属性,请参见此处的此问题的答案:stackoverflow.com/questions/12722246/… => 所以将 LinearLayout 更改为 RelativeLayout对我来说听起来不错
【解决方案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 的宽度)。但是,列表的高度更大,图像的大小也很好! (但列表是空的...)
  • @user3340507 你是否在列表视图中添加了android:layout_weight="1"。
猜你喜欢
  • 2013-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-29
相关资源
最近更新 更多