New Guy
New Guy

Reputation: 596

Android Vertical Switch Widget

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.

Upvotes: 11

Views: 4926

Answers (3)

metamonkey
metamonkey

Reputation: 457

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>

Upvotes: 13

mmprog
mmprog

Reputation: 781

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

Upvotes: 0

roiberg
roiberg

Reputation: 13747

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".

Upvotes: 0

Related Questions