How to Rotate TextView?
I want to rotate TextView but I can't get proper output. I am getting textView
with missing some text
In Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_marginTop = "50dip">
<TextView android:layout_width="wrap_content" android:gravity="bottom"
android:layout_height="wrap_content" android:id="@+id/text"
android:text="Shreeji \n Nath" />
</RelativeLayout>
In Animation
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="40" android:toDegrees="-90" android:pivotX="40%"
android:duration="0">
</rotate>
Java file
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.widget.TextView;
public class VDemo ex开发者_开发知识库tends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.text);
RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this,R.anim.myanim);
ranim.setFillAfter(true);
tv.setAnimation(ranim);
}
}
Added in API level 12
view.animate().rotationBy(90).start()
Change the main.xml to :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_alignParentLeft="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="TextView" android:layout_marginTop="50dip"
android:layout_marginLeft="50dip" android:id="@+id/text1"></TextView>
</RelativeLayout>
精彩评论