10

Using android, I'd like to get a vertical switch widget implementation in place. As far as I can tell, it looks like switches only have a horizontal orientation. I'd like to have something like the following:

enter image description here

After looking through the threads here and searching google, I have yet to find something that can give me this. Everything I search for gives me the horizontal implementation only.

so I can generate your 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 doesn't seem to be a good way to set the orientation. I know that the question is a bit high level. Is there some attribute that is immediately available that will allow me to have a vertical switch? Or will I have to create a custom switch and possibly modify the onDraw method so that it is flipped vertically? Any help is appreciated. Thanks.

New Guy
  • 566
  • 1
  • 8
  • 28
  • Wait why the down vote? I have a question about something that I researched and was unable to come up with an answer for. I gave a pictoral reprsentation of what I am looking for as well... As I said, any help is appreciated. – New Guy Jan 05 '15 at 14:00

3 Answers3

13

Try android:rotation="90" like this:

 <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>
metamonkey
  • 427
  • 7
  • 33
  • 1
    So easy! But there's a catch! The rotation also rotates any text, too. Separating the text into another TextView isn't that hard though. – SMBiggs Sep 13 '16 at 21:05
0

There is no quick attribute for vertical orientation.. Sorry :) First you can look at the code of the switch and see if you can copy and manipulate it. Second you can just implement your on. Have a layout with a button inside it. use onTouchListener to slide it from side to side. No need to use "onDraw".

roiberg
  • 13,629
  • 12
  • 60
  • 91
0

Try toggle button witch graphics and use pictures like this You included in Your post. Here is example of such toggle buttons: Toggle button using two image on different state

Community
  • 1
  • 1
mmprog
  • 771
  • 10
  • 21