Android开关 - 如何使拇指比轨道小?

时间:2016-08-02 00:50:39

标签: android xml widget

这段代码会产生一个拇指图像,无论我尝试实现什么样的填充,它总是触及轨道的两侧。如何调整拇指9补丁图像的大小/移位,使其在轨道内部具有边距?

activity_main.xml:
        <Switch
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"

        android:thumb="@drawable/my_button_toggle"

        android:layout_marginTop="100dp"
        android:rotation="90"
        android:id="@+id/icon"
        android:track="@drawable/customtrack"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"

my_toggle_button.xml:

        <?xml version="1.0" encoding="utf-8"?>
        <selector xmlns:android="http://schemas.android.com/apk/res/android">


        <item android:state_checked="false"                                                                          
         android:drawable="@drawable/diiveinkrbcv3noanten"
            />
        <item android:state_checked="true"  
        android:drawable="@drawable/diiveinkrbcv3"

            />

        </selector>

customtrack.xml


    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true">
        <shape android:shape="rectangle"
            android:visible="true"
            android:dither="true"
            android:useLevel="false">

            <gradient android:startColor="#FF9AB9F2"
                android:endColor="#FF3139A1"

               />
            <stroke android:width="5px" android:color="#3C53577B" />

            <corners android:radius="15dp"/>

            <size android:width="27dp"
                android:height="37dp" />
        </shape>
    </item>

    <item android:state_checked="false">
        <shape android:shape="rectangle"
            android:visible="true"
            android:dither="true"
            android:useLevel="false">

            <gradient android:startColor="#FF9AB9F2"
                android:endColor="#FF3139A1"

               />
            <stroke android:width="5px" android:color="#3C53577B" />
            <corners android:radius="15dp"/>

            <size android:width="27dp"
                android:height="37dp"
                />
        </shape>
    </item>

</selector>

输出:

Target device: lge-nexus_5x-00df78af20e1beed
Installing APK: C:\Users\Jake\AndroidStudioProjects\Dyve\Dyve\app\build\outputs\apk\app-debug.apk
Uploading file to: /data/local/tmp/com.biapps.Diive
Installing com.biapps.Diive
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.biapps.Diive"
    pkg: /data/local/tmp/com.biapps.Diive
Success


Launching application: com.biapps.Diive/com.biapps.makin_biscuits.MainActivity.
DEVICE SHELL COMMAND: am start -D -n "com.biapps.Diive/com.biapps.makin_biscuits.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet.
Client not ready yet.
Client not ready yet.
Client not ready yet.
Client not ready yet.
Client not ready yet.
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.biapps.Diive/com.biapps.makin_biscuits.MainActivity }
Connected to the target VM, address: 'localhost:8600', transport: 'socket'

0 个答案:

没有答案