2010-12-31 30 views

Trả lời

1

Đối với những người có cùng vấn đề tôi sau gần như giương lên tôi có ý tưởng về cách lấy dải phân cách.

tôi đã thêm dòng chia ở dưới cùng của bố trí tùy chỉnh của tôi cho mỗi mục

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" style="@style/ListItem2"> 

    <TextView android:id="@+id/Text" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_alignParentLeft="true" 
     style="@style/SpinnerView_Text" android:paddingLeft="10dip" /> 

    <ImageView android:id="@+id/icon" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:src="@drawable/arrowright" 
     android:layout_alignParentRight="true" android:layout_centerInParent="true" 
     android:layout_marginRight="20dip" /> 

</RelativeLayout> 

<ImageView android:id="@+id/Divider1" android:layout_width="fill_parent" 
    android:layout_height="1dip" style="@style/Divider"></ImageView> 

+0

bạn có thể đăng xml hơn? ví dụ bố cục ngoài cùng và kiểu/Divider.thank bạn – pengwang

11

tôi quản lý để tìm một giải pháp thích hợp hơn cho vấn đề này (mà không bao gồm cả dải phân cách trong bố cục mục đơn).

Những gì bạn phải làm là xác định trong chủ đề của hoạt động của bạn

 <item name="android:dropDownListViewStyle">@style/App.Style.Spinner</item> 

và sau đó tạo ra phong cách phù hợp với

<style name="App.Style.Spinner" parent="@style/Widget.Sherlock.Light.ListView.DropDown"> 
      <item name="android:dividerHeight">10dip</item> 
      <item name="android:divider">@drawable/mydivider</item> 
    </style> 
+6

Điều này thật tuyệt nếu bạn không áp dụng kiểu này cho chỉ 1 Spinner trong Hoạt động. – Paul

+1

Nơi nào chúng tôi xác định mục: ' @ style/App.Style.Spinner' Bạn có ý nghĩa gì bởi "trong chủ đề hoạt động của bạn"? Có một chút bối rối về điều này. –

+0

@ojonugwaochalifu Bạn phải xác định mục này là một phần của chủ đề hoạt động của bạn ... – Talihawk

9

này đã làm việc cho tôi:

<style name="SpinnerStyle" parent="Widget.AppCompat.ListView.DropDown"> 
     <item name="android:divider">#d1d1d1</item> 
     <item name="android:dividerHeight">0.5dp</item> 
    </style> 

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:dropDownListViewStyle">@style/SpinnerStyle</item> 

Ưu điểm của việc sử dụng này là nó không loại bỏ hiệu ứng gợn trên di chuột.

+1

nó hoạt động +1 cho giải pháp đơn giản và dễ dàng. Cảm ơn –

1

Dựa trên câu trả lời @Talihawk, tôi đã làm cho nó hoạt động cho cụ thể chỉ dành cho spinner. Thay vì đặt chủ đề hoạt động của bạn, thiết lập các chủ đề trực tiếp cho xem spinner:

<style name="MatchSpinnerStyle" parent="android:style/Widget.ListView.DropDown"> 
    <item name="android:divider">#123456</item> 
    <item name="android:dividerHeight">1dp</item> 
</style> 

<style name="MatchSpinnerTheme" parent="AppTheme"> 
    <item name="android:dropDownListViewStyle">@style/MatchSpinnerStyle</item> 
</style> 

<android.support.v7.widget.AppCompatSpinner 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"   
    android:theme="@style/MatchSpinnerTheme"/> 
+0

+1. Ngoài ra, tôi phải thêm, bạn có thể xác định dải phân cách của bạn trong một 'drawable' và tham chiếu nó thay vì' # 123456'. Oh và 'android: theme' phải được sử dụng thay cho' stlye = "@ stye/..." ' – Sevastyan

Các vấn đề liên quan