14

私は物事のUI側を学ぼうとしているAndroidの初心者であり、頭を悩ませています.これが私が今持っているものです:

breedes_listing.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content">
    <ListView android:id="@+id/breedsListView"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:dividerHeight="0px" android:divider="#00000000"></ListView>
</LinearLayout>

breeds_listing_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:background="@drawable/list_item_background"
    android:orientation="horizontal" >
    <TextView android:id="@+id/allbreeds_single_item"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:gravity="center_horizontal"></TextView>
</LinearLayout>

list_item_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#043402" />
    <stroke android:width="3dp" color="#ffff8080" />
    <corners android:radius="8dp" />
    <padding android:left="10dp" android:top="10dp" android:right="10dp"
        android:bottom="10dp" />
</shape>

私が理解するのに苦労しているのは、選択したアイテムをどのようにスタイルするかです? 現時点では、選択されたアイテムの背景は恐ろしいオレンジ色で、丸みを帯びた緑色の長方形の下にオレンジ色のアウトライン効果があります。私はベスト プラクティスに沿って物事を行っていないと確信しているので、提案や改善は大歓迎です。

どうもありがとう、D.

4

2 に答える 2

27

私はこれをします :

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

   <item android:state_pressed="true">
       <shape  >
         <solid android:color="#929292" />
       </shape>
   </item>



   <item>
     <shape  >
        <solid android:color="#FFFFFF" />
     </shape>
   </item>

 </selector>

したがって、このプロパティを使用できますandroid:state_pressed="true"

私の例では、セルの背景は白のみになり、押されると灰色になります。

それが役立つことを願っています!

于 2010-10-29T11:46:41.170 に答える
3

StateListDrawableを使用する必要があります。

ここで ListView 項目の例を見つけることができます。

アイテムが選択されたときに特定の色/ドローアブルが必要な場合は、 を使用しますandroid:state_focused="true"

于 2010-10-29T16:39:03.773 に答える