1

カスタム配列アダプターを使用してリストビューをセットアップしましたリストは正常に表示されますグラデーションと各アイテムの背景も使用しましたが、コードにはタップ時にグラデーションを変更するように記載されていますが、これは発生しません。以下は私のxmlです

main.xml

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

         android:id="@+id/list"
         android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:dividerHeight="0.1dp"
    android:listSelector="@drawable/list_selector"

     />

行リスト.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>


<TextView
    android:id="@+id/txtListText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:padding="20dp"
    android:textSize="35sp"
    android:textColor="#545454"
    android:background="@drawable/ogbg" 
    />

</LinearLayout>

list_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->

<item
 android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/ogbg" />

   <item android:state_pressed="true"  
        android:drawable="@drawable/ogpress" />

    <item android:state_selected="true"
       android:state_pressed="false"
        android:drawable="@drawable/ogpress" />

</selector>

ogbg.xml// 通常の背景グラデーション

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
  android:shape="rectangle">
<gradient 
android:startColor="#FFFAFAFA" 
android:centerColor="#FFFFFFFF" 
android:endColor="#FFFFFFFF" 
android:angle="90"/>
</shape>

ogpress.xml //タップで変化するグラデーション

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

android:shape="rectangle">
<gradient 
android:startColor="#FF05c1ff" 
android:endColor="#7F05c1ff" 
android:angle="90"/>
</shape>
4

1 に答える 1

0

私は過去に同様の問題を抱えていました。セレクター項目の順序を入れ替えてみてください。理由はわかりませんが、セレクターの動作は項目の順序に依存します。これが機能しない場合は、「選択済み」と「押された」を分離してみてください。州ごとに追加の項目を実行します。

于 2013-01-17T12:17:05.220 に答える