カスタムシェイプスイッチの下に動作していないトラックとセレクタのサイズは以下のようになります。カスタムスイッチ - 21 API
APIの上にAPI 21
以下は21
<size/>
のようなブロックは、pre21 APIの<shape/>
では機能しません。
これを解決する方法はありますか?
CODE
container.xml:
<Switch
android:id="@id/switch_follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textOff=""
android:textOn=""
android:thumb="@drawable/switch_selector"
android:track="@drawable/switch_track"/>
描画可能/ switch_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item
android:bottom="@dimen/switch_selector_padding"
android:left="@dimen/switch_selector_padding"
android:right="@dimen/switch_selector_padding"
android:top="@dimen/switch_selector_padding">
<shape
android:dither="true"
android:shape="oval"
android:useLevel="false"
android:visible="true">
<gradient
android:angle="270"
android:endColor="@color/primary_white"
android:startColor="@color/primary_white"/>
<corners
android:radius="@dimen/switch_radius"/>
<size
android:width="@dimen/switch_track_height"
android:height="@dimen/switch_track_height" />
</shape>
</item>
</layer-list>
</item>
</selector>
描画可能/ switch_track.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:shape="rectangle"
android:useLevel="false"
android:visible="true">
<gradient
android:angle="270"
android:endColor="@color/primary_yellow_dark_v2"
android:startColor="@color/primary_yellow_dark_v2"/>
<corners android:radius="@dimen/switch_radius" />
<stroke
android:width="@dimen/switch_stroke_height"
android:color="@android:color/transparent">
</stroke>
<size
android:width="@dimen/switch_track_width"
android:height="@dimen/switch_track_height" />
</shape>
おそらく誰かが同様の問題に直面しました。あなたの経験を共有してください。
EDIT:追加dimensは、私はあなたのコードをコピーしてswitch_track_widthを持っている必要があり<size>
widthプロパティの内側にあなたの描画可能/ switch_selector.xmlで、私のマシンで最初のものを実装しようとしている
<dimen name="switch_track_width">36dp</dimen>
<dimen name="switch_track_height">30dp</dimen>
<dimen name="switch_radius">50dp</dimen>
<dimen name="switch_selector_padding">2dp</dimen>
<dimen name="switch_stroke_height">0dp</dimen>
てください投稿@ DIMEN/switch_track_widthと高さのサイズの正しい半径の定義の直径の半分の
thumbTextPadding
。 – Warpzit@Warpzit、私の編集を確認してください – AnZ
XMLタグが間違っていると思います。 XML構文エラー(これは以前のバージョンではうまくいきましたが、不可能ではないと思われます...)に起因する場合を除き、xmlはプレーンテキストまたは ".ini"のようにデータファイルのフォーマットユーザーになります実際には何もしないで、あまりにも多くの質問で使用される形式。 – bitifet