Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 532
New Guy Avatar asked Jan 05 '15 12:01

New Guy


1 Answers

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>
like image 88
metamonkey Avatar answered Oct 15 '22 05:10

metamonkey