仕切りのあるリストビューとエキスパンドビューを使用して設定できますが、スピナーではアイテム間に仕切りがないように見えます。
これを修正する方法を知っている人はいますか?
仕切りのあるリストビューとエキスパンドビューを使用して設定できますが、スピナーではアイテム間に仕切りがないように見えます。
これを修正する方法を知っている人はいますか?
これは私のために働いた:
<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>
これを使用する利点は、ホバー時の波及効果が除去されないことです。
この問題のより適切な解決策を見つけることができました (単一アイテムのレイアウトに仕切りを含めずに)。
あなたがしなければならないことは、あなたの活動のテーマで定義することです
<item name="android:dropDownListViewStyle">@style/App.Style.Spinner</item>
次に、適切なスタイルを作成します
<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>
同じ問題を抱えている人のために、私はほとんどあきらめた後、仕切りを取得する方法のアイデアを得ました。
各アイテムのカスタムレイアウトの下部に仕切り線を追加しました
<?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>
他の解決策はどれもうまくいかなかったので、スピナーアイテムの背景としてドローアブルを使用して、目的の効果を生み出しました。
新しいdropdown_divider.xml
Drawable とカスタム SpinnerAdapter クラスを作成し、getDropDownView()
メソッドを適用して背景を Spinner アイテムに設定しました。
ドローアブルのandroid:bottom="-56dp"
は、2 つのアイテム間の線を完全に中央に配置するものですが、それは、レイアウトに適用した正確なマージンとパディングに依存します。
dropdown_divider.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:left="16dp"
android:right="16dp"
android:bottom="-56dp">
<shape android:shape="line" >
<stroke
android:width=".2dp"
android:color="#FF666666" />
</shape>
</item>
</layer-list>
SpinnerAdapter
:
@Override
public View getDropDownView(int position, View convertView,
@NonNull ViewGroup parent) {
TextView text = (TextView) super.getDropDownView(position, convertView, parent);
text.setBackground(context.getDrawable(R.drawable.dropdown_divider));
label.setTextColor(Color.BLACK);
label.setText(lists.get(position).getTitle());
return text;
}