我怎样才能让我的ListView行高度不同 [英] How can I make my listview rows different heights

查看:269
本文介绍了我怎样才能让我的ListView行高度不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在如果存在即2行中的高度列表项,那么所有的行是两行高度

Right now if there is a list item that is 2 lines in height then all the rows are two lines in height

如何才能让独立于其他行的行的高度。

How can I make the rows' height independent on other rows.

的ListView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/user_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null" />

</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="1dp"
    android:paddingTop="1dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp" >

    <TextView
        android:id="@+id/user_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:maxLines="2"
        android:ellipsize="middle"
        android:textColor="@android:color/holo_blue_dark"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/points"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:gravity="right"
        android:textStyle="bold" />

</LinearLayout>

我使用的延伸BaseAdapter的自定义适配器。在getView没有什么特别的,只是一个viewholder百通我不改变高度或任何

I am using a custom adapter extending BaseAdapter. the getView there is nothing special, just a viewholder patern I don't change height or anything

推荐答案

你为什么不尝试使高度= 0dp体重1

why don't you try making the height = 0dp and weight 1

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:paddingBottom="1dp"
    android:paddingTop="1dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp" >

    <TextView
        android:id="@+id/user_name"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:maxLines="2"
        android:ellipsize="middle"
        android:textColor="@android:color/holo_blue_dark"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/points"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:gravity="right"
        android:textStyle="bold" />

</LinearLayout>

更新:

检查这个答案

http://stackoverflow.com/a/7513423/1932105

这篇关于我怎样才能让我的ListView行高度不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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