分享

listview怎样设置每个Item的高度?

 dmw_zgl 2014-11-20
       1.在ListView的布局文件中把属性android:layout_height设置成"wrap_content"
 <ListView 
	  android:cacheColorHint="#00000000"
	  android:textColor="#ff435346"
	  android:textSize = "20sp"
	  android:id="@id/android:list" 
	  android:layout_width="fill_parent" 
	  android:layout_height="wrap_content"
	  android:layout="@+id/textViewCurrentBase"
	  android:listSelector="#00000000"
	  android:drawSelectorOnTop="false"/>


2.设置子项xml文件(比如这里把一个item.xml设置成ListView的一行)的各个控件android:layout_height的值。这里80sp+40sp就是你需要的一行的高度了。
item.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas./apk/res/android" 
    android:id="@+id/TextView01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    >
  <TextView android:focusable="false" 
      android:textColor="@drawable/white"
      android:id="@+id/ItemTitle"
      android:layout_height="80sp" 
      android:layout_width="fill_parent" /> 
  <TextView android:focusable="false" 
      android:id="@+id/ItemText" 
      android:textColor="@drawable/blue"
      android:layout_height="40sp" 
      android:layout_width="wrap_content" 
      android:layout_below="@+id/ItemTitle" /> 
  <Button 
      android:id="@+id/ItemButton" 
      android:layout_height="wrap_content"
      android:layout_width="wrap_content" 
      android:layout_alignParentRight="true" />
</RelativeLayout>

希望有用。     

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约