Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android:How to rotate LinearLayout

Tags:

java

android

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg2x" >
<LinearLayout 
    android:id="@+id/linear"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_alignParentTop="true"
    android:background="#FF00FF00"
  >
    <TextView 

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FF000000"
        android:textSize="70dp"
        android:text="test linearlayout"
        />

</LinearLayout>

Now I wanna Rotate the "linear" layout by 90 degrees. * And I dont wanna use Animation*, is there any other way to achive this? Please help me.Thanks in advance!!

like image 589
Rocky Avatar asked Dec 04 '12 08:12

Rocky


2 Answers

Since you don't need animation, from API 11 or above, you can use

android:rotation = "90"

to rotate in XML itself. If you want to do it in code, say after a button click, then you can use its java equalant too

 yourLayout  = (LinearLayout) findViewById(R.id.your_id);
 yourLayout.setRotation(90.0f);

But not before API 11. See documentation.

android:rotation

rotation of the view, in degrees.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol rotation.

EDIT: After seeing comment

yeah,I know this method in API level 11. But what about lower api level?

I think you can have to rotate the view yourselves. And I believe the lchorus and Pete's answer in this thread does work. For Pete's answer he is using animation, but you can set animation duration of 0 to do it without any visible animation. There is no other straight forward way as far as I know..

like image 117
Krishnabhadra Avatar answered Sep 18 '22 21:09

Krishnabhadra


Using this library you can rotate whole view hierarchy https://github.com/rongi/rotate-layout

Like this

enter image description here

like image 25
Dmitry Ryadnenko Avatar answered Sep 21 '22 21:09

Dmitry Ryadnenko