ListView交替行颜色除了列

时间:2012-03-12 12:08:08

标签: android xamarin.android

当选择行时,我在每行上交替使用ListView和两个list_selector.xml获取特殊颜色。但我的问题是每行有4个'列'(实际上是4个textview),第一列应该在所有行中具有相同的颜色。这样就完成了,但是当我选择一行时,第一列的颜色仍然存在。我该怎么控制呢?

ListItem.axml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:id="@+id/lstItemAlumno"
    android:background="@android:color/transparent"
    android:orientation="horizontal" >


<!--This textView has the same color in every row-->
  <TextView
       android:id="@+id/lbHour"
       android:layout_weight="1"
       android:layout_height="fill_parent"
       android:layout_width="0dip"
       android:gravity="center"
       android:textStyle="bold"
       android:background="@color/columnColor" 
       android:text="Hour" />

  <TextView
     android:id="@+id/lbGrupo"
     android:layout_weight="1"
     android:layout_height="wrap_content"
     android:layout_width="0dip"
     android:gravity="center"
     android:textStyle="bold"
     android:text="Grupo" />

  <TextView
     android:id="@+id/lbAsignatura"
     android:layout_weight="1"
     android:layout_height="wrap_content"
     android:layout_width="0dip"
     android:gravity="center"
     android:textStyle="bold"
     android:text="Asig" />

  <TextView
     android:id="@+id/lbAula"
     android:layout_weight="1"
     android:layout_height="wrap_content"
     android:layout_width="0dip"
     android:gravity="center"
     android:textStyle="bold"
     android:text="Aula" />


</LinearLayout>

list_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_selected="false" android:state_pressed="false"  android:drawable="@color/white" />
  <item android:state_pressed="true" android:drawable="@color/orange_list" />
  <item android:state_selected="true" android:state_pressed="false"  android:drawable="@color/orange_list" />
</selector>

List_selector_2.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_selected="false" android:state_pressed="false"  android:drawable="@color/grey_list" />
  <item android:state_pressed="true" android:drawable="@color/orange_list" />
  <item android:state_selected="true" android:state_pressed="false"  android:drawable="@color/orange_list" />
</selector>

在我的ListAdapter.cs中,我在GetView方法中使用列表选择器:

(...)
            if (position % 2 != 0)
                view.SetBackgroundResource(Resource.Drawable.list_selector);
            else
                view.SetBackgroundResource(Resource.Drawable.list_selector_2);

            return view;

0 个答案:

没有答案