2014-03-25 59 views
0

我想爲我的ListView的每一行獲得像背景一樣的玻璃。但是使用下面的代碼,我得到了一個像整個Listview背景的玻璃。我只是希望玻璃像每行的背景。我在下面發佈我的xml代碼。請建議如何獲得像背景一樣的玻璃而不是整個ListView。如何自定義ListView行以獲取玻璃背景?

XML文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".Lists" 
    android:background="@drawable/backgnd" > 


<ListView 
    android:id="@+id/listView1" 
    android:layout_width="fill_parent" 
    android:layout_height="250dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:longClickable="true" 
    android:background="#20535252" 
    android:layout_below="@+id/relativeLayout1" > 
</ListView> 
+0

使用'自定義Adapter'和你使用的適配器getView方法設置'Background'要你'自定義適配器Layout' –

+0

? –

+0

我正在使用SimpleAdapter。是否有可能使用SimpleAdapter? – user3256145

回答

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".Lists" 
    android:background="@drawable/backgnd" > 


<!-- your custom views --> 
</RelativeLayout> 

現在使用此佈局誇大你的ListView的項目。 您可以使用自定義適配器是這樣的: -

public class YourAdapter extends BaseAdapter { 



     public int getCount() { 
      return ItemList.size(); 
     } 

     public Object getItem(int position) { 
      return ItemList.get(position); 
     } 

     public long getItemId(int position) { 
      return position; 
     } 

     public View getView(int position, View view, ViewGroup parent) { 

//inflate your layout here :- 
      if(view ==null) 
       view = layoutInflater.inflate(R.layout.yourLayout, null); 


      return view; 

     } 

    }