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