wrap_content 用于列表视图的宽度 [英] wrap_content for a listview's width

查看:26
本文介绍了wrap_content 用于列表视图的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 ListView 与最长的行相等?为 ListView 的宽度设置 wrap_content 没有效果.ListView 水平覆盖整个屏幕.

Is there a way to have a ListView with the with equal to the longest row? Setting wrap_content for the ListView 's width has no effect. The ListView covers the whole screen horizontally.

这是活动布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView   android:id="@+id/listview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/country_picker_bg" />

这是行 xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:layout_marginBottom="@dimen/padding"
    android:padding="@dimen/padding"
    android:background="@drawable/white_round_rect" >
    <TextView android:id="@+id/title"
        style="@style/GreyTextView"
        android:layout_marginLeft="@dimen/padding"/>    
    <ImageView  
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:src="@drawable/orange_arrow_selector"/>
</LinearLayout>

谢谢,格拉茨

推荐答案

有没有办法让 ListView 与最长的行相等?

Is there a way to have a ListView with the with equal to the longest row?

不,部分原因是我们无法知道最长的一行是什么.

No, in part because we have no way to know what the longest row is.

假设您将 ListAdapter 附加到 ListView,其中 ListAdapter 上的 getCount() 返回1,234,567 的值.要确定最长行的宽度,我们必须创建每一行并检查其宽度.这需要几个小时,而用户在这些时间里不会开心.

Let's say that you attach a ListAdapter to the ListView, where getCount() on the ListAdapter returns a value of 1,234,567. To determine the width of the longest row, we would have to create each row and examine its width. This would take hours, and the user will not be happy during those hours.

这篇关于wrap_content 用于列表视图的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆