canvas教程

Android Canvas编程:对rotate()和translate()两个方法的研究(2)

字号+ 作者:H5之家 来源:H5之家 2017-10-29 11:40 我要评论( )

我们把代码修改如下: public class MyTextView extends TextView {public MyTextView(Context context, AttributeSet attrs) {super(context, attrs);}@Overrideprotected void onDraw(Canvas canvas) {canvas.rot

我们把代码修改如下:

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,怎么样?是不是很简单?

 

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • Canvas教程(16)

    Canvas教程(16)

    2017-10-29 15:00

  • 天天学名言:Life is a great big canvas, and you should throw

    天天学名言:Life is a great big canvas, and you should throw

    2017-10-28 16:00

  • canvas仿新浪微博头像截取上传的实例分享

    canvas仿新浪微博头像截取上传的实例分享

    2017-10-27 17:00

  • canvas图表详解系列(5):雷达(面积)图

    canvas图表详解系列(5):雷达(面积)图

    2017-10-26 10:01

网友点评
"