Android中设置ListView的item高度无效--解决方案

原文地址:https://blog.csdn.net/zhonglinliu/article/details/54580622

问题:

     ListView的使用中,item是在adapter中用来显示每一个小条目的数据结构,也是一个xml文件,应用非常灵活和广泛,这里说一个经常遇到的问题,对于刚接触Android的朋友应该会有疑惑,就是设置ListView的item高度无效

解决方案:

        其实非常简单,我们只需要在xml文件中给item设置一个minHeight就搞定啦!,如下:

         这个item的高度就是200dp.

    <?xml version="1.0" encoding="utf-8"?>  
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        android:orientation="horizontal"  
        android:layout_width="fill_parent"  
        android:layout_height="50dip"  
        android:minHeight="200dp"  
        >  
        <TextView  
            android:id="@+id/tv"  
            android:layout_width="fill_parent"   
            android:layout_height="20dp"   
            android:text="@string/hello"  
            />  
    </LinearLayout>  
 

猜你喜欢

转载自blog.csdn.net/chenhuakang/article/details/81086610