WRAP_CONTENT的ListView的宽度 [英] wrap_content for a listview's width

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

问题描述

有没有办法让同一个ListView与等于最长行?设置WRAP_CONTENT为ListView的宽度没有影响。 ListView控件水平覆盖整个屏幕。

这是该活动的布局

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>
< ListView的机器人:ID =@ + ID /列表视图
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=@可绘制/ country_picker_bg/>
 

和这是行的xml

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的LinearLayout
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:重力=center_vertical
    机器人:layout_marginBottom =@扪/填充
    机器人:填充=@扪/填充
    机器人:背景=@可绘制/ white_round_rect>
    < TextView的机器人:ID =@ + ID /标题
        风格=@风格/ GreyTextView
        机器人:layout_marginLeft =@扪/填充/>
    < ImageView的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:SRC =@可绘制/ orange_arrow_selector/>
< / LinearLayout中>
 

感谢您, 的Gratzi

解决方案
  

有没有办法让同一个ListView与等于最长行?

没有,部分原因是因为我们没有办法知道最长的行是什么。

比方说,您可以将 ListAdapter 的ListView ,其中 getCount将() ListAdapter 返回的值1,234,567 。要确定最长排的宽度,我们必须创建每一行,并检查它的宽度。这将需要几个小时,并且用户将不会在这些小时高兴。

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.

This is the activity layout

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

and this is the row 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>

Thank you, Gratzi

解决方案

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.

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的ListView的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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