如何创建与Android的用户触摸事件一个可调整大小的矩形? [英] How to create a resizable rectangle with user touch events on Android?

查看:586
本文介绍了如何创建与Android的用户触摸事件一个可调整大小的矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建的矩形形状,将与用户的触摸的大小。下面的图片是我想要做的一个很好的例子:

I want to create a rectangular shape that will be resized with the touches of the user. Below image is a good example of what i want to do:

有没有那方面的例子吗?什么我需要学习来实现这一点?

Is there any example like that? What do I need to study to implement this?

在此先感谢,

推荐答案

要实现自定义视图,你来源于视图类:)覆盖的OnDraw()于容貌,覆盖的onTouchEvent()输入处理。需要注意的是Android中,您不能在视图中绘制外的OnDraw();如果要刷新视图,叫无效()

To implement a custom view, you derive a class from View :) Override onDraw() for looks, override onTouchEvent() for input processing. Note that in Android, you cannot draw on view outside onDraw(); if you want to refresh the view, call invalidate().

您可以实现拖动角落,不同的看法。于容貌,只是用现成图像(随时从的ImageView 导出)。拖动实现为移动您的视图以响应触摸事件。 RelativeLayout的是你的朋友任意视图​​positining。

You can implement draggable corners as separate views. For looks, just use ready-made images (feel free to derive from ImageView). Dragging is implemented as moving your view in response to touch events. RelativeLayout is your friend for arbitrary view positining.

您可以添加自制的意见,以布局;只要到XML编辑并键入< com.mypackage.MyViewClass> 元素

You can add homemade views to the layout; just go to XML editing and type a <com.mypackage.MyViewClass> element.

这篇关于如何创建与Android的用户触摸事件一个可调整大小的矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆