gpt4 book ai didi

android - 在 android 中像简单形状(正方形和圆形)的设计者一样开发 View

转载 作者:太空狗 更新时间:2023-10-29 15:07:13 25 4
gpt4 key购买 nike

你好,我已经为此苦苦挣扎了一段时间,试图构建一种设计器,我可以通过点击(或拖动)将一些形状放入其中,问题是我试图理解 Touch gestures他们谈论视口(viewport)、滚动和拖动以创建图表,但我的目标是更像 map 设计,像这样:

enter image description here

到目前为止,我已经能够做一些基本的事情,比如当你触摸它时它会画一个圆圈并且能够缩放,但我仍然不理解整个视口(viewport)、内容和 OverScroller 的组合。你能给我一些建议吗?有没有人这样做过?任何可以以简单方式解释的教程或示例。

最佳答案

您可以使用此函数将方形位图更改为圆形位图

public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
// TODO Auto-generated method stub
int targetWidth = 50;
int targetHeight = 50;
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
targetHeight,Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(((float) targetWidth - 1) / 2,
((float) targetHeight - 1) / 2,
(Math.min(((float) targetWidth),
((float) targetHeight)) / 2),
Path.Direction.CCW);

canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(),
sourceBitmap.getHeight()),
new Rect(0, 0, targetWidth,
targetHeight), null);
return targetBitmap;
}

再看看Path类的这些方法

path.addArc(oval, startAngle, sweepAngle);
path.addOval(oval, dir);
path.arcTo(oval, startAngle, sweepAngle);

关于android - 在 android 中像简单形状(正方形和圆形)的设计者一样开发 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20777567/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com