相关疑难解决方法(0)

如何在Android中更改Switch的高度和宽度

  1. 我想把开关放在120dp宽度和30dp高度上.
  2. 另外我想在拇指上没有文字,但是想要将拇指盖在总宽度的一半,所以我希望它是60dp.
  3. 此外,我希望拇指的高度可以从三个侧面看到背景开关的高度.

我不知道如何做#3和#1和#2,我尝试了下面的xml,但它不起作用:

 <Switch
         android:id="@+id/plug_switch"
         android:layout_width="120dip"
         android:layout_height="10dp"
         android:maxHeight="10dp"
         android:layout_below="@id/plug_graph_layout"
         android:layout_centerHorizontal="true"
         android:minWidth="100dp"
         android:thumb="@drawable/plugs_button"
         android:track="@drawable/btntoggle_selector"
         android:textOn=""
        android:textOff=""
         android:width="120dip" />
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我#1,#2和#3.

谢谢

android switch-statement

8
推荐指数
2
解决办法
2万
查看次数

Switch-Button拇指歪斜了吗?

我的Switch按钮的拇指似乎变得歪斜(开启和关闭状态).在github上也有类似的问题,但那些是人们在API 4.0中使库支持Switch按钮 -

main包含开关按钮,并且有一个拇指和轨道可绘制的应用程序

这就是发生的事情:

在此输入图像描述

这就是它的假设:

在此输入图像描述

switch_track_on.png

在此输入图像描述

main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<Switch
    android:id="@+id/switch1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="112dp"
    android:thumb="@drawable/switch_thumb_selector"
    android:track="@drawable/switch_track_selector"
    android:textOn=""
    android:textOff=""/>

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

switch_thumb_selector.xml

<selector>
<item android:drawable="@drawable/switch_thumb">
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)

switch_track_selector.xml

    <selector>
<item android:drawable="@drawable/switch_track_on" android:state_checked="true"/>
<item android:drawable="@drawable/switch_track_off" android:state_checked="false"/>
</selector> 
Run Code Online (Sandbox Code Playgroud)

xml android android-switch

8
推荐指数
3
解决办法
7891
查看次数

标签 统计

android ×2

android-switch ×1

switch-statement ×1

xml ×1