Android vertical textview text vertical bar

Source: Internet
Author: User

Vertical text control:

package com.howfun.test;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);   }}

To align the text on the left:

    <com.howfun.test.VerticalTextView        android:layout_width="450dp"        android:layout_height="450dp"        android:textSize="40sp"        android:layout_marginLeft="100dp"        android:gravity="bottom|right"        android:text="Vertical text"        />

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.