Android Vertical Display TextView

Source: Internet
Author: User

Android Vertical Display TextView

1 because of the interface requirements, need to textview vertical display, not much to say, look at the code, I am also an example of search, in this thank you to write this example of the great God, here to make a note and share to everyone

2. Using the knowledge of custom controls, let's look at how to customize the

The Java code is as follows:

Package com.android.xxx;

Import Android.content.Context;

Import Android.graphics.Canvas;
Import Android.util.AttributeSet;
Import android.view.Gravity;
Import Android.widget.TextView;

public class Verticaltextview extends textview{
Final Boolean topdown;


Public Verticaltextview (context context, AttributeSet Attrs) {
Super (context, attrs);
final int gravity = Getgravity ();
if (gravity.isvertical (Gravity) && (gravity&gravity.vertical_gravity_mask) = = Gravity.bottom) {
Setgravity ((Gravity&gravity.horizontal_gravity_mask) | Gravity.top);
Topdown = false;
}else
Topdown = true;
}

@Override
protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {
Super.onmeasure (Heightmeasurespec, Widthmeasurespec);
Setmeasureddimension (Getmeasuredheight (), Getmeasuredwidth ());
}


@Override
protected Boolean setframe (int l, int t, int r, int b) {
Return Super.setframe (L, T, L + (B-T), t+ (r-l));
}

@Override
public void Draw (canvas canvas) {
if (Topdown) {
Canvas.translate (GetHeight (), 0);
Canvas.rotate (90);
}else {
Canvas.translate (0, GetWidth ());
Canvas.rotate (-90);
}
Canvas.cliprect (0, 0, getwidth (), GetHeight (), Android.graphics.Region.Op.REPLACE);
Super.draw (canvas);
}
}

And then look at the layout in the XML layouts file

The wording of this control:

<com.android.xxx.verticaltextview
Android:id= "@+id/xxxname"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_centervertical= "true"
Android:layout_alignparentright= "true"
android:layout_marginright= "14DP"
Android:textsize= "27DP"
Android:gravity= "Bottom|right"
Android:maxlength= "15"
android:visibility= "Visible"
Android:textcolor= "#ffffff"
/>

Android Vertical Display TextView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.