如何改变Android Switch轨道的宽度?

Nei*_*lDA 21 java android

我对这个小问题感到很疯狂.我有一个'切换'表单小部件,但无论我尝试多少,我都不能让它更窄.即使我有一个字符而不是'ON'或'OFF',开关的大小也保持不变.'拇指'变小,但必须拖动与之前相同的距离.将'layout_width'更改为较小的值只会切断剩余的轨道.'minWidth'似乎什么也没做.

谁知道我怎么做到这一点?理想情况下,我只想要一个空的拇指,我会用拇指颜色代码知道哪个是哪个.

XML代码:

<Switch
     android:id="@+id/switch3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Switch"
     android:textOff=" "
     android:textOn=" " />
Run Code Online (Sandbox Code Playgroud)

我开始说: 在此输入图像描述

但是我想要这样的东西: 在此输入图像描述

BSK*_*NIA 57

在此属性中设置所需的开关宽度.

机器人:switchMinWidth

喜欢

<Switch
android:id="@+id/switchVisitAgain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="1dp"
android:checked="false"
android:gravity="center_vertical"
android:switchMinWidth="56dp"
android:textOff=""
android:textOn=""
android:thumb="@drawable/round_button"
android:track="@drawable/button_black" />
Run Code Online (Sandbox Code Playgroud)

谢谢,bskania

  • 花了差不多两个星期找出解决方案,总是不停地尝试"setminWidth"你是一个救星!PS:switchMinWidth ="0dp"就是我用的.这样,开关根据可绘制的比例缩放 (6认同)
  • 这修剪了开关的左侧部分。关于如何实现对称交换机的任何建议? (2认同)
  • 无法正确设置小于2x拇指的宽度~ /sf/ask/1453374331/#54420782 (2认同)