开发者

How to deal with transparent listview in Android

I have created four tabs using tabhost, and placed four listviews in each like below:

public class prem extends ListActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    String[] names = new String[] { "Pr"};


    this.setListAdapter(new ArrayAdapter<String>(this,
            R.layout.simple_list_item_checked, names));
}

Problem is I have created background images for each listview but when I scroll the listview goes black.I know that I should add android:cacheColorHint="#00000000" to the xml file to make the listview transparent, so I have created a new xml and id and tried to add android:cacheColorHint="#00000000" in the xml to make transparent, but it just force closes;

this.setListAdapter(开发者_运维问答new ArrayAdapter<String>(this, R.layout.list_item, R.id.listb, names));

?xml version="1.0" encoding="utf-8"?>

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    <TextView android:text="@+id/TextView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="30px"></TextView>
     <ListView android:id="@+id/listb" 
     android:layout_height="wrap_content"
     android:layout_width="fill_parent">
     </ListView>
</LinearLayout>


Have you tried to add setCacheColorHint(00000000) in the prem java file?

ListView lv = getListView();    
lv.setCacheColorHint(00000000);    
lv.setAdapter(new ArrayAdapter<String>(this,
        R.layout.simple_list_item_checked, names));


android:cacheColorHint=#00000000 should do the trick. Where in your layout XML did you put it? It should go in ListView, for example:

<ListView
    ...
    android:cacheColorHint="#00000000"
    ...
/>


The Android Developers' blog had a post about that a while ago. According to their post "Why is my list black? An Android optimization", all you need to do is add the android:cacheColorHint="#00000000" attribute to the ListView element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜