实现textview内容竖直显示
public class VerticalTextView extends TextView{
final boolean topDown;
public VerticalTextView(Context context,AttributeSet attrs){
super(context,attrs);
int gravity = getGravity();
if(Gravity.isVertical(gravity)&&
(gravity&Gravity.VERTCAL_GRAVITY_MASK)==Gravity.BOTTOM){
setGravity((gravity&Gravity.HORIZONTAL_GRAVITY_MASK)|Gravity.TOP);
topDown = false;
}else{
topDown = true;
}
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredHeight(),getMeasuredWidth());
}
protected boolean setFrame(int l,int t,int r, int b){
return super.setFrame(l,t,l+(b-t),t+(r-l));
}
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(),Region.Op.REPLACE);
super.draw(canvas);
}