目的
设计一个手绘图形的画板
工具及环境
使用java语言,在Android studio平台上进行开发
功能设计
实现一个可以绘图的画板,界面有相关的选择按钮。可以根据按钮切换画笔的颜色,刷子可以加粗画笔的线条大小,橡皮可以用于抹除已经绘制的图案,清屏可实现清屏重置画板
设计思路
首先设计界面,然后设计按钮点击功能。橡皮擦的功能可通过把画笔颜色设置与背景颜色一致来实现,清屏功能可通过背景重置覆盖原背景实现
代码
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.xdw.exercise.HandWrite
android:id="@+id/handwriteview"
android:layout_width="fill_parent"
android:layout_height="600dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:layout_weight="1"
android:text="红色" />
<Button
android:id="@+id/blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"