目的
设计一个可以移动的小球,当小球被拖到一个矩形块中时退出程序
工具及环境
使用java语言,在Android studio平台上进行开发
功能设计
实现小球可点击或拖动进行移动,当小球移动至矩形块范围内则退出程序
设计思路
通过画笔绘制出一个小球和一个矩形块,然后实现小球的可移动功能,最后实现获取坐标,当小球所处坐标位于矩形块内时,退出程序
代码
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.example.firstapp.MainActivity" >
<com.example.firstapp.TestView
android:layout_width="fill_parent"
android:layout_height="fill_parent" />