사용자 정의 모양 스위치 아래에 작동하지 트랙과 선택의 크기는 다음과 같습니다사용자 정의 스위치 - (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 :
01,235,<?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>
아마도 누군가 비슷한 문제에 직면했을 것입니다. 귀하의 경험을 공유하십시오.
편집 : 추가 dimens 내가 코드를 복사 switch_track_width을 가져야한다 <size>
폭 건물 내부에 드로어 블/사진 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