2011-12-05 25 views
6

Tôi có một ListView trong đó mỗi mục danh sách là bố cục tùy chỉnh dựa trên RelativeLayout, có thể nhấp và nó có bộ chọn tùy chỉnh. Ngoài ra, nó có một RelativeLayout phụ mà cũng có thể nhấp và nó có bộ chọn riêng của nó.Chế độ xem được trạng thái có thể kéo (được nhấn, v.v ...) từ bố cục

Something như thế này:

--------------- 
|    | 
|   ___ | 
|  | | | 
--------------- 

Tất cả mọi thứ hoạt động hoàn hảo nhưng vấn đề là khi tôi bấm vào cách bố trí tương đối phụ huynh, chọn con giả định trạng thái của bộ chọn mẹ. Tôi đã cố gắng đặt

android:duplicateParentState="false" 

nhưng không có gì thay đổi.

Bất kỳ ý tưởng nào? Cảm ơn trước

Trả lời

2

Bạn có thể vui lòng hiển thị mã của bạn về mục và bộ chọn của ListView không? Để tâm trí của tôi bạn đã thực hiện một số sai lầm, khi thực hiện nó. Đây là ví dụ về mục và bộ chọn của nó. Nó hoạt động tốt đối với tôi:

Video, cách thực hiện của tôi làm việc: >click to open<

list_view_item.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="40dp" 
    android:background="@drawable/relative_selector"> 

    <RelativeLayout 
     android:layout_width="300dp" 
     android:layout_height="100dp" 
     android:background="@drawable/child_selector_1" 
     android:clickable="true"> 

     <RelativeLayout 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_centerHorizontal="true" 
      android:background="@drawable/child_selector_2" 
      android:clickable="true"/> 
    </RelativeLayout> 
</RelativeLayout> 

relative_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="true"> 
     <inset xmlns:android="http://schemas.android.com/apk/res/android"> 
      <shape android:shape="rectangle"> 
       <solid android:color="@android:color/holo_blue_bright" /> 
      </shape> 
     </inset> 
    </item> 
</selector> 

child_selector_1.xml

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

    <!-- pressed state --> 
    <item android:state_pressed="true"> 
     <inset xmlns:android="http://schemas.android.com/apk/res/android"> 
      <shape android:shape="rectangle"> 
       <solid android:color="@android:color/holo_orange_dark" /> 
      </shape> 
     </inset> 
    </item> 

    <!-- focused state --> 
    <item android:state_focused="true"> 
     <inset xmlns:android="http://schemas.android.com/apk/res/android"> 
      <shape android:shape="rectangle"> 
       <solid android:color="@android:color/holo_orange_dark" /> 
      </shape> 
     </inset> 
    </item> 

    <!-- normal state --> 
    <item> 
     <inset xmlns:android="http://schemas.android.com/apk/res/android"> 
      <shape android:shape="rectangle"> 
       <solid android:color="@android:color/holo_red_dark" /> 
      </shape> 
     </inset> 
    </item> 
</selector> 
Các vấn đề liên quan