In Android we can rotate text view after API Level 11 .
In android sdk using public void setRotation (float rotation) method
on Textview we can rotate Text.
and here rotation parameter is The degrees of rotation.
Example:
In below example we can see diffrence between normal TextView and rotated TextView.
UI Layout(text_roation.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/rotationtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="androidsurya(RotationText)"
android:textColor="#00FF00"
android:textStyle="bold" />
<TextView
android:id="@+id/normaltextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/normaltextview"
android:layout_alignParentTop="true"
android:layout_marginTop="18dp"
android:text="androidsurya(NormalText)"
android:textColor="#00FF00"
android:textStyle="bold" />
</RelativeLayout>
Android Activity(TextRoationActivity.java)
package com.androidsurya.textrotation;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class TextRoationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_roation);
TextView rotationTextview = (TextView) findViewById(R.id.rotationtextview);
rotationTextview.setRotation(85);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.text_roation, menu);
return true;
}
}
Register Activity in AndroidManifest file
<activity
android:name="com.androidsurya.textrotation.TextRoationActivity"
android:label="@string/app_name" >
Output Screenshot:
Note : In AndroidManifest file minsdk level should be "11"
<uses-sdk
android:minSdkVersion="11" />
In android sdk using public void setRotation (float rotation) method
on Textview we can rotate Text.
and here rotation parameter is The degrees of rotation.
Example:
In below example we can see diffrence between normal TextView and rotated TextView.
UI Layout(text_roation.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/rotationtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="androidsurya(RotationText)"
android:textColor="#00FF00"
android:textStyle="bold" />
<TextView
android:id="@+id/normaltextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/normaltextview"
android:layout_alignParentTop="true"
android:layout_marginTop="18dp"
android:text="androidsurya(NormalText)"
android:textColor="#00FF00"
android:textStyle="bold" />
</RelativeLayout>
Android Activity(TextRoationActivity.java)
package com.androidsurya.textrotation;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class TextRoationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_roation);
TextView rotationTextview = (TextView) findViewById(R.id.rotationtextview);
rotationTextview.setRotation(85);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.text_roation, menu);
return true;
}
}
Register Activity in AndroidManifest file
<activity
android:name="com.androidsurya.textrotation.TextRoationActivity"
android:label="@string/app_name" >
Output Screenshot:
Note : In AndroidManifest file minsdk level should be "11"
<uses-sdk
android:minSdkVersion="11" />
No comments:
Post a Comment