简体   繁体   English

如何创建自定义Android视图? 使用XML对象还是绘图API?

[英]How to create a custom Android view? Using XML objects or a drawing API?

I'm trying to create a new view that would: 我正在尝试创建一个新的视图,该视图将:

  • load an image 加载图像

  • allow the user to zoom and rotate the image with two fingers while a "cropping box" stays translucent over the top while the image extends beyond the "cropping box" 允许用户用两根手指缩放和旋转图像,同时“裁剪框”在顶部保持半透明,而图像超出“裁剪框”

  • with the end goal of being able to mark the rotation and position of the main image (so that later i could crop out or show the area within the cropping box) 最终目标是能够标记主图像的旋转和位置(以便以后我可以裁剪出或显示裁剪框中的区域)

I'm wondering if I can do this with an ImageView holding the image in the background and another ImageView holding the crop box on top of it, then using TouchEvents to move the image, would this work? 我想知道是否可以通过将ImageView放在背景中并将另一个ImageView放在其顶部的裁剪框,然后使用TouchEvents移动图像来TouchEvents这一点?

Or do I need to use some drawing API on a 2D surface? 还是我需要在2D曲面上使用一些绘图API?

I'm just really new to creating custom objects in Android that aren't just customized out-of-the-box Views. 对于在Android中创建不仅仅是自定义的即用型视图的自定义对象,我真的很陌生。

What's the standard way of creating something like this? 创建这样的东西的标准方法是什么?

Thanks! 谢谢!

Create a Compound View by extending RelativeLayout with two overlapping ImageView s in it. 通过扩展RelativeLayout并在其中包含两个重叠的ImageView创建Compound View Then override onTouch event or override onGestureDetector interface in that newly created View. 然后覆盖该新创建的View中的onTouch事件或onGestureDetector接口。

Official Documentation: http://developer.android.com/guide/topics/ui/custom-components.html Another Tutorial: http://www.vogella.com/tutorials/AndroidCustomViews/article.html 官方文档: http : //developer.android.com/guide/topics/ui/custom-components.html另一个教程: http : //www.vogella.com/tutorials/AndroidCustomViews/article.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM