简体   繁体   中英

removing whitespace in android Switch which is devoted to text

(we all know) There are three parts in android Switch Widget ... Text - Thumb - Track.
My question is how can we completely remove this text part if we don't want to use any text because it's ruining the balance of the layout
在此处输入图片说明

You simply have to not provide any text:

    <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

Use negative margin for the switch as follows and see if it works:

 <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-10dp" />

I know some people consider it a bad practice to use negative margin but right it seems to be the easiest way.

You can set margin programmatically as well based on device type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM