Android Vertical Switch Widget

Using android, I would like to implement a vertical switch widget implementation. As far as I can tell, the switches seem to have a horizontal orientation. I would like to have something like the following:

enter image description here

After looking at the topics here and searching google, I still need to find something that can give me this. Everything I'm looking for gives me only horizontal implementation.

so I can create a typical horizontal switch

<Switch android:id="@+id/switch_button" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_alignLeft="@+id/label" android:layout_gravity="center" android:switchMinWidth="130dp" android:thumb="@drawable/switch_selector" android:track="@drawable/track_selector" > </Switch> 

but there seems to be no good way to set the orientation. I know the question is a little high. Is there some kind of attribute that is immediately available that will allow me to have a vertical switch? Or do I need to create a custom switch and possibly change the onDraw method so that it flips vertically? Any help is appreciated. Thanks.

+5
source share
3 answers

Try android: rotation = "90" as follows:

  <Switch android:id="@+id/switch_button" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_alignLeft="@+id/label" android:layout_gravity="center" android:switchMinWidth="130dp" android:thumb="@drawable/switch_selector" android:track="@drawable/track_selector" android:rotation="90"> </Switch> 
+4
source

There is no quick attribute for vertical orientation .. Sorry :) First you can look at the switch code and see if you can copy and manipulate it. Secondly, you can just realize yours. You have a layout with a button inside. use onTouchListener to move it from side to side. No need to use "onDraw".

0
source

Try switching witch graphics and use photos like this. You have included in your post. Here is an example of such toggle buttons: Toggle button using two images in different states

0
source

Source: https://habr.com/ru/post/1210402/


All Articles