我在我的HomeLayout中有listview(android.support.v7.widget.RecyclerView)。在HomeLayout所選項目不能在列表視圖
<LinearLayout
p1:orientation="horizontal"
p1:minWidth="25px"
p1:clickable="true"
p1:minHeight="25px"
p1:layout_width="wrap_content"
p1:layout_height="45dp"
p1:id="@+id/linearLayout2"
p1:layout_alignParentTop="true"
p1:layout_alignParentLeft="true"
p1:layout_marginLeft="70dp"
p1:layout_marginTop="15dp"
p1:layout_marginRight="310dp">
<android.support.v7.widget.RecyclerView
p1:id="@+id/categoriesListView"
p1:duplicateParentState="true"
p1:state_checked="true"
p1:focusable="true"
p1:focusableInTouchMode="true"
p1:clickable="true"
p1:scrollbars="horizontal"
p1:state_activated="true"
p1:layout_width="match_parent"
p1:layout_height="45dp" />
</LinearLayout>
列表視圖
代碼定製適配器。 適配器代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="horizontal"
p1:focusable="true"
p1:focusableInTouchMode="true"
p1:clickable="true"
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/linearLayout1">
<TextView
p1:text="Medium Text"
p1:background="@drawable/designforselected"
p1:textAppearance="?android:attr/textAppearanceMedium"
p1:layout_width="wrap_content"
p1:layout_height="45dp"
p1:id="@+id/txtCategoryName"
p1:textSize="20dp"
p1:focusable="true"
p1:focusableInTouchMode="true"
p1:clickable="true"
p1:textColor="@drawable/textcolorarticle"
p1:gravity="center"
p1:fontFamily="Myriad"
p1:paddingRight="20dp"
p1:paddingLeft="20dp"
p1:paddingTop="10dp"
p1:paddingBottom="10dp"
p1:layout_marginLeft="5dp" />
</LinearLayout>
的TextView有按定製設計p1:background="@drawable/designforselected"
代碼designforselected是
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle"/>
<solid android:color="#333333" />
</item>
<item android:state_pressed="true" >
<shape android:shape="rectangle"/>
<solid android:color="#333333" />
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#b3b3b3"
android:endColor="#e6e6e6"
android:angle="90"/>
<corners
android:topLeftRadius="5dp" android:topRightRadius="5dp" android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp" >
</corners>
</shape>
</item>
</selector>
State_pressed是工作,但state_selected沒有工作。爲什麼?泰 我想解決XML文件
我想解決XML文件 –