2012-06-28 9 views
35

que tiene este ImageView en mi diseño:fuente Girar ImageView del archivo de diseño xml

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

Es un divisor horizontal. Quiero rotarlo 90 grados, así que tengo un divisor vertical.
¿Hay alguna manera posible de hacerlo aquí desde el diseño y no la clase Activity?

+0

sólo se puede ajustar la altura a 'layout_height = "fill_parent"' y entonces va a ser estirada en todo el diseño – thepoosh

+0

aceptan amablemente/Upvote la respuesta si usted tiene su solución :) –

+0

@thepoosh: La imagen de origen no es un cuadrado. Es un rectángulo ancho y, al hacer lo que dices, dará como resultado un rectángulo vertical delgado. – mehrmoudi

Respuesta

104

Puede utilizar Disponible Desde Nivel API 11

android:rotation="90" 

código final para poner,

<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" /> 
+1

¡Gracias, pero no hay tal atributo para ImageView, al menos en el mío! http://s15.postimage.org/gpit1dvrd/Untitled.png – mehrmoudi

+0

@Mehran Visite http://developer.android.com/reference/android/view/View.html#attr_android:rotation Para obtener más información –

+1

No estoy de acuerdo: android : el atributo roation solo está disponible desde API 11: http://developer.android.com/reference/android/R.attr.html#rotation –

1

Usted puede hacer que su código mediante la creación de un nuevo objeto de mapa de bits. mira esto: http://android-er.blogspot.fr/2010/07/rotate-bitmap-image-using-matrix.html Y específicamente esta función

Matrix matrix = new Matrix(); 
matrix.postScale(curScale, curScale); 
matrix.postRotate(curRotate); 

Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true); 
myImageView.setImageBitmap(resizedBitmap); 
Cuestiones relacionadas