切换(缩略图和跟踪)Android

fun*_*kie 5 java xml android

伙计们!我有一个问题:)尝试自定义一个开关,例如开关的轮廓将带有边框,在开关的内部,您单击以激活事件的边框也带有边框,但是在一种不会与开关的轮廓边框重叠的方式。由于我没有足够的代表,因此我实际上无法发布图片,因此我希望它足够清楚:)到目前为止,我得到的是:

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

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <size android:height="50dp"/>
    <corners
        android:radius="3dp"/>

    <stroke
        android:width="2dp"
        android:color="@color/wampRed"/>

</shape>


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

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/wampRed"/>
    <corners
        android:radius="2dp"/>


</shape>
Run Code Online (Sandbox Code Playgroud)

<

Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/switchButton"
        android:layout_marginBottom="40dp"
        android:textOn=""
        android:thumb="@drawable/shape_track"
        android:track="@drawable/shape_thumb"
        android:layout_marginRight="5dp"
        android:textOff="       "
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/dateOutput"

        />
Run Code Online (Sandbox Code Playgroud)

小智 0

如果您尝试使拇指小于轨道,并且两者都有轮廓,则应该为每个创建两个自定义可绘制对象。拇指可绘制对象应该是“图层列表”,以便您可以在拇指周围添加填充以使其不与轨道重叠。

以拇指为例:

<layer-list>
    <item 
        android:top="@dimen/thumb_padding"
        android:left="@dimen/thumb_padding"
        android:right="@dimen/thumb_padding"
        android:bottom="@dimen/thumb_padding">
        <shape android:shape="oval">
            <solid android:color="@color/your_color"/>
            <size
                android:height="@dimen/thumb_diameter"
                android:width="@dimen/thumb_diameter"/>
        </shape>
    </item>
 </layer-list>
Run Code Online (Sandbox Code Playgroud)

对于轨道:

<shape android:shape="rectangle">
            <corners android:radius="@dimen/track_radius" />
            <size 
              android:height="@dimen/switch_height"
              android:width="@dimen/switch_width"/>
            <stroke
              android:width="@dimen/your_outline_thickness"
              android:color="@color/your_color"/>
        </shape>
Run Code Online (Sandbox Code Playgroud)

如果您的意思不同,我会尝试快速编辑