2015-04-23 79 views
0

我要顯示在自定義列表視圖如何使用透明背景

透明背景圖像顯示在自定義列表視圖圖像這是我的XML代碼

<ListView 
    android:id="@+id/list" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#00000000" > 

</ListView> 

這是我的貨品代碼

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
<TableRow> 
    <ImageView 
     android:id="@+id/img" 
     android:layout_width="50dp" 
     android:background="#00000000" 
     android:layout_height="50dp"/> 

    <TextView 
     android:id="@+id/txt" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" /> 

</TableRow> 
</TableLayout> 

這是我的.java代碼

ListView list; 
String[] web = { 
     " Profile", 
     " Help And Support", 
     " Account Settings", 
     " Location Settings", 
     " Notifications", 
} ; 
Integer[] imageId = { 
     R.drawable.profile2, 
     R.drawable.help, 
     R.drawable.account, 
     R.drawable.location, 
     R.drawable.notification, 

}; 
    CustomList adapter = new CustomList(settings.this, web, imageId); 
    list=(ListView)findViewById(R.id.list); 
    list.setAdapter(adapter); 
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 
      Toast.makeText(settings.this, "You Clicked at " + web[+position], Toast.LENGTH_SHORT).show(); 

     } 
    }); 

請幫助我。如何設置圖像的透明背景顏色。

+0

其中是您的'CustomList'代碼和列表項xml代碼? –

+0

請檢查您使用的圖像是否具有透明背景 –

+0

請添加您的輸出屏幕截圖以及customList適配器以獲取更多詳細信息。 – Dhaiyur

回答

0

默認情況下,imageview的背景應該是透明的。這是imageview與imagebutton比較的區別。確保你在自定義適配器的getView()方法中使用了setImageResource而不是setBackground。當然如果你的圖像可以繪製本身的背景,你必須使用任何照片編輯軟件將其刪除。我通常上傳PNG圖像,具有透明背景

imageView.setImageResource(imageId[position]);