我们把代码修改如下:
public class MyTextView extends TextView { public MyTextView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { canvas.rotate(-90); canvas.translate(-getHeight(), 0); super.onDraw(canvas); } }<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.carrey.demo.myTextView.MyTextView android:layout_width="wrap_content" android:layout_height="100dip" android:text="测试文字" android:layout_alignParentBottom="true" /> </RelativeLayout>结果如下:
在左下方显示出了我们想要的竖直TextView,怎么样?是不是很简单?