那你就在父容器中设置背景么,或者给你的ListView 加一个Linearlayout,把Linearlayout的背景设置成你的图片

解决方案 »

  1.   

    要加在listview的里面,不要加在listview对应的每一行的xml里面
      

  2.   

    你的listView里面的布局是自己写的还是自定义的,你这个效果的原因可能是因为你在listView的布局文件(即每一个Item的布局)中设置的背景,而不是在ListView中设置的背景这样设置:
    <ListView android:id="@+id/listView"
    android:background="@drawable/background"
    ......
    .....
    </ListView>
      

  3.   

     public class TestStringList extends Activity implements 
       OnItemClickListener {  
     public void onItemClick1(AdapterView<?> arg0, View arg1, int arg2, long arg3) {  
     this.setTitle("You Click Item:" + String.valueOf(arg2));   
     }  
     private ListView mListView = null;  
     @Override  
     protected void onCreate(Bundle savedInstanceState) {  
    // TODO Auto-generated method stub  
     super.onCreate(savedInstanceState);  
     mListView = new ListView(this);  
     mListView.setOnItemClickListener(this);  
     ArrayAdapter<String> adapter = new ArrayAdapter<String>
       (this,R.layout.simple_list_item_checked,  
     new String[]{"Item1","Item2","Item3","ItemA", "ItemB", "ItemC"}); 
     mListView.setAdapter(adapter);  
     this.setContentView(mListView);  
     }
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub

    }  
     } 我是定义在simple_list_item_checked里面的,代码如下:
      <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center_vertical"
        
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:scrollingCache="false"
         
         android:background="@drawable/list_selector_background"
    />
      

  4.   

    是不是还要另外定义一个listview的xml阿?如果是的话xml在那里引用?
      

  5.   

    ArrayAdapter<String> adapter = new ArrayAdapter<String>
      (this,R.layout.simple_list_item_checked,   
     new String[]{"Item1","Item2","Item3","ItemA", "ItemB", "ItemC"});你是对adapter做的设置,那simple_list_item_checked就这是每一项的xml了。
    主要是this.setContentView(mListView);   你指定这个页面就加载一个listview了,需要创建一个main.xml的布局,里面添加你的listview,就如3L所说的那样,然后程序中 @Override   
     protected void onCreate(Bundle savedInstanceState) {   
    // TODO Auto-generated method stub   
     super.onCreate(savedInstanceState);   
     this.setContentView(R.id.main);
     mListView = (ListView)findViewbyId(R.id.listview);   
     mListView.setOnItemClickListener(this);   
     ArrayAdapter<String> adapter = new ArrayAdapter<String>
      (this,R.layout.simple_list_item_checked,   
     new String[]{"Item1","Item2","Item3","ItemA", "ItemB", "ItemC"});  
     mListView.setAdapter(adapter);   
        
     }这样
      

  6.   

    还是不行java代码:
     public class TestStringList extends Activity implements 
       OnItemClickListener {  
     public void onItemClick1(AdapterView<?> arg0, View arg1, int arg2, long arg3) {  
     this.setTitle("You Click Item:" + String.valueOf(arg2));   
     }  
     private ListView mListView = null;  
     @Override  
     protected void onCreate(Bundle savedInstanceState) {  
    // TODO Auto-generated method stub  
     super.onCreate(savedInstanceState);   
     setContentView(R.layout.main);
     mListView = (ListView)findViewById(R.id.listview);   
     mListView.setOnItemClickListener(this);   
     ArrayAdapter<String> adapter = new ArrayAdapter<String>
      (this,R.layout.simple_list_item_checked,   
     new String[]{"Item1","Item2","Item3","ItemA", "ItemB", "ItemC"});
     
     mListView.setAdapter(adapter);  
     this.setContentView(mListView);  
     }
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub

    }
      
    main.xml如下:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <ListView android:id="@+id/listview"
    android:background="@drawable/disabled_focus"
     android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    </ListView>
    </LinearLayout>
      

  7.   


    是的,需要。要引用要在ListView的setAdapter方法里进行引用。
      

  8.   

    晕,那你这样:main.xml如下:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:background="@color/white"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      >
    <ListView android:id="@+id/listview"
     android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    </ListView>这样背景就是白色了,自己加个colors.xml添加一个颜色
    </LinearLayout>
      

  9.   

    setContentView(R.layout.main);
     this.setContentView(mListView);   这两个可以一起用马?
    还有楼上的,你说的我试过,但问题貌似不在这里,还应该是java代码的问题我觉得,
    求高手解惑
      

  10.   

    如果显示不完全,再设置android:cacheColorHint为0x00000000,透明
      

  11.   

    不能一起用,setContentView是加载界面。只能加载一个
      

  12.   

    回楼上:我觉得这俩不能一起用,可是现在我想改listiew背景的同时还要修改adapter,应该怎么弄呢
      

  13.   

    我说的方法不行么?adapter中指定的是每项list的背景,和整个背景无关,你直接修改TestStringList的背景颜色就可以了吧,就是我10L回复的方式,我这里试了,是可以的。
      

  14.   

    谢谢楼上,我已经知道问题出在哪里了,谢谢你哦 
    ,你说的那个没错,我把listSelector没有家进去,呵呵 ,非常感谢哦