removing whitespace in android Switch which is devoted to text

﹥>﹥吖頭↗ 提交于 2019-12-25 06:04:56

问题


(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


回答1:


You simply have to not provide any text:

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



回答2:


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.



来源:https://stackoverflow.com/questions/25292103/removing-whitespace-in-android-switch-which-is-devoted-to-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!