-->

Implement vertical TextView by calling setRotation()

Advertisemen
API Level 11 provide setRotation(float rotation) method to rotate a View. We can call the method of TextView object to make it display in vertical.

vertical TextView

Layout:
<LinearLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:textStyle="bold|italic"
android:layout_gravity="center_horizontal"
android:background="#B0B0B0" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
android:id="@+id/verticaltextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android-er"
android:textStyle="bold"
android:textColor="#00FF00"
android:layout_gravity="center"
android:background="#808080" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:textColor="@android:color/white"
android:gravity="center"
android:background="#505050" />

</LinearLayout>

</LinearLayout>


Java code, call setRotation() to display the TextView (verticalTextView) in vertical.
package com.example.androidtextview;

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

TextView verticalTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

verticalTextView = (TextView)findViewById(R.id.verticaltextview);
verticalTextView.setRotation(90);
}


}


remark: Have to modify AndroidManifest.xml to set android:minSdkVersion="11" or higher.

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.
Related Posts
Disqus Comments
© Copyright 2017 GENERAL INFO FOR ANDROID DEVELOPMENT - All Rights Reserved - Template Created by goomsite - Proudly powered by Blogger