我是android新手。 用listview遇到一个问题,就是listview选中一行的时候,只有有字的地方高亮。挺难看。如图:
如何选中一整行呢?高手快来。

解决方案 »

  1.   

    在你的drawable文件夹下建一个xml文件,定义一些样式,然后在ListView定义的xml中用backgroud或src引用它。
      

  2.   

    我想,大概是你ListView的每一个Item设定得不好吧。比如说你的每一个Item都是一个TextView ,那么其实就不好,其实你可以设置这个TextView 的布局么。但是我仍然建议,你把TextView都装进LinearLayout的一个实例中,然后把LinearLayout的实例设定好属性 。
      

  3.   


    那我再试.  我是用了 str + "                                                 " ;的形式避过了这个问题.
      

  4.   

    如果一行只有一个TextView的话,把属性设置下:android:layout_height="fill_parent" android:layout_width="fill_parent"
      

  5.   

    你的ListView的每一个Item是不是都是一个TextView呢、如果是的话,把下面两个属性都设置为“fill_parent”,
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    我个人认为你应该是把
    android:layout_width="wrap_content"
    设置成这样了。
      

  6.   

    item没有设好,楼主好好设定下……
      

  7.   

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:layout_height="fill_parent">
      
    <TextView android:id="@+id/ItemTextView" android:layout_width="fill_parent" android:layout_height="fill_parent"></TextView>
    </LinearLayout>
    还不行啊.我都设了. 莫非是什么灵异事件?
      

  8.   

    补充一下,我现在是用的 android 1.5 的这个sdk . 因为这个开发的通用行好啊. 是不是这个的影响? 我终于搞好了. 设成fillparent不行, 设置了一个超过屏幕的长度. 600px ,这样, 就行了. 
    不过同样谢谢各位, 正确的代码贴上来 同时再问,难道我这是歪解?
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:layout_height="50px">
    <ImageView android:id="@+id/ImageViewLI" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    <TextView android:id="@+id/ItemTextView" android:layout_height="fill_parent" android:layout_width="600px"></TextView>
    </LinearLayout>
      

  9.   

    楼主weight要做布局的话一定要用好比重。你这样设置绝对宽度是不行的,在多台手机上可能分辨率不同导致界面更难看。。你设置好比重的话就哦了。比如你上面你把imageview和textview的比重设置一下你把textview设置为1  imageview不设置的话imageview就只会填充剩余的空间
      

  10.   

    貌似这个问题跟weight没有关系
      

  11.   


    谢谢,答复 . 我用了weight试了一下. 我发现, 如果是这样:<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="50px" android:layout_width="fill_parent">
    <ImageView android:id="@+id/ImageViewLI" android:layout_height="wrap_content" android:layout_width="fill_parent"></ImageView>
    <TextView android:id="@+id/ItemTextView" android:layout_height="fill_parent" android:layout_weight="5" android:layout_width="fill_parent"></TextView>
    </LinearLayout>显示效果和原来的那个相同 . 也就是说虽然LinearLayout 设置了 fill_parent的宽度,但显示的时候还是那么宽. Weight的用法我学习了一下,很好. 但确实和这个无关. 我现在就总结一下,解决这个问题的几个关键点. 1 我首先设置了listitem对应的layout,讲这个layout中的linearlayout,和textview都设置成了fill_parent
      但这样还是不行. 2 我又到包含listview的layout中,讲listview的width设置成了fill_parent ,还是不行. 3 我又在包含listview的layout中,讲listview的上层,linearlayout的width设置成fill_parent ,OK了!楼上朋友说的weight指的是相对长度,也就相当于html中的20%之类.  比如左右两个空间比例是1和5 ,那就设置weight为 1 和 5 , 就能实现. 总体来说,要想使得选中高亮覆盖整个行,你需要从最顶层到这个listview,所有的width都要设置成fill_parent才行 . 好了给分. 
      

  12.   

    问题出在你的LinearLayout只有一个,这时候他填充整个面板认为是最外层,你在里面在建一个LinearLayout宽度为fill_parent,在将你的textview放在里面,就没问题了<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="fill_parent"
        android:weightSum="1"
        > <LinearLayout android:orientation="horizontal"
    android:layout_height="24pt"
    android:layout_width="fill_parent" android:weightSum="1">"
         <ImageView android:id="@+id/msgimg" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_margin="7px"
    android:layout_marginLeft="9pt"
    android:layout_gravity="center_vertical"/>
    <TextView android:id="@+id/title" 
    android:layout_width="100pt"
    android:layout_height="wrap_content" 
    android:textSize="22px"
    android:textColor="#000000"
    android:layout_gravity="center_vertical" 
    android:layout_marginLeft="3pt"
    /> </LinearLayout>
    </LinearLayout>
      

  13.   

    还有一种方法,就是设置你LinearLayout 宽度为一个数。比喻200pt
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_height="50px" android:layout_width="200pt">
    <ImageView android:id="@+id/ImageViewLI" android:layout_height="wrap_content" android:layout_width="fill_parent"></ImageView>
    <TextView android:id="@+id/ItemTextView" android:layout_height="fill_parent" android:layout_weight="5" android:layout_width="fill_parent"></TextView>
    </LinearLayout>
      

  14.   

    listview的width设置成fill_parent,就可以了。
      

  15.   

    listview的width设置成fill_parent。