Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate ImageView source from layout xml file

I have this ImageView in my layout:

<ImageView android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:contentDescription="@string/image_divider"         android:paddingBottom="8dp"         android:paddingTop="4dp"         android:scaleType="fitXY"         android:src="@android:drawable/divider_horizontal_textfield" /> 

It's a horizontal divider. I want to rotate it 90 degrees so I have a vertical divider.
Is there any possible way to do it right here from the layout and not the Activity class?

like image 564
mehrmoudi Avatar asked Jun 28 '12 11:06

mehrmoudi


People also ask

How do you rotate a view in Swift?

rorateview.swiftlet bitmap: CGContext = UIGraphicsGetCurrentContext()! //Move the origin to the middle of the image so we will rotate and scale around the center. let newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!

How do I rotate a picture on my Android?

Drag the dots to the edges of your desired photo or tap Auto. To rotate a photo 90 degrees, tap Rotate . To make minor adjustments to straighten the photo, use the dial above Rotate . To automatically straighten the photo, tap Auto.

Can ImageView be clickable?

You can make a view clickable, as a button, by adding the android:onClick attribute in the XML layout. For example, you can make an image act like a button by adding android:onClick to the ImageView. In this task you create a prototype of an app for ordering desserts from a café.


2 Answers

You can use Available Since API Level 11

android:rotation="90" 

Final Code to Put,

<ImageView android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:rotation="90"         android:contentDescription="@string/image_divider"         android:paddingBottom="8dp"         android:paddingTop="4dp"         android:scaleType="fitXY"         android:src="@android:drawable/divider_horizontal_textfield" /> 
like image 118
RPB Avatar answered Sep 22 '22 17:09

RPB


Add "id" at ImageView (if not generate auto):

 android:id="@+id/imageView" 

and use the "id" (kotlin example):

val imageView = findViewById<ImageView>(R.id.imageView) imageView.setRotation(90f) // rotate 90 degree 
like image 36
Levente Tiszberger Avatar answered Sep 25 '22 17:09

Levente Tiszberger