读书人

android 几何图形的作图

发布时间: 2012-08-26 16:48:06 作者: rapoo

android 几何图形的绘制
以前的文章里边画一般都是一些矩形,今天就看看怎么在android手机屏幕上绘制一些几何图形,如三角形、多边形、椭圆、圆形、正方形 等等。并且设置 空心、实心。下面我们先来看看
在android中可以绘制出那些几何图形

方法 说明
drawRect 绘制矩形
drawCircle 绘制圆形
drawOval 绘制椭圆
drawPath 绘制任意多边形
drawLine 绘制直线
drawPoin 绘制点

我们先看看运行效果---------------------。。。。。


下面我们看例子吧
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textColor="#00FF00"
/>
<xiaohang.zhimeng.GameView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
红色的部分 是我们自己实现的 GameView此类继承了View 我们把它作为布局文件的一部分加载了进来。
下边是代码
Activity01 比较简单 但是为了保持完整我还是贴上来吧。

  

读书人网 >图形图像

热点推荐