图像/位图放置?
你们有人见过 Android 中的模拟器 Bong 应用程序吗?您将如何制作该应用程序?例如,我尝试使用 xml 布局来做到这一点。我将图片分开并按顺序和分段放置,以便当按下特定图片时会出现一个功能。问题是,在不同的手机上,集体图片的大小要么超出屏幕,要么被压缩。
我还尝试使用带有位图的 SurfaceView,以便每个单独的图片都可以采用屏幕的大小并相应地调整它们。我无法使图片不重叠在一起,而是按顺序排列在屏幕上。我可以让前两个很好地指定矩形 dst,起始高度是另一个结束的位置,但第三个和第四个没有显示在屏幕上。例如,我使用了
Rect dst = new Rect(0, 0, mWidth, mHeight/7 );
顶部的第一张图像。然后对于第二张图像
Rect dst = new Rect(0, mHeight/7, mWidth, mHeight/3 );
(mHeight 和 mWidth 是画布的宽度和高度)
不知道如何将接下来的两张图片放置在它们和彼此的下面。我尝试
Rect dst = new Rect(0, mHeight/7+(mHeight/3), mWidth, mHeight/7);
过但没有成功。老实说,它看起来非常简单,我确信它是,但我似乎无法让图像按照我想要的方式工作。有没有一种方法可以将图像保留为一个整体,并指定何时选择某个点,它会执行某些操作(这在每部手机上都以相同的方式工作)。
任何对此的帮助将不胜感激。关于如何获得我想要的结果的任何其他想法也非常感谢。感谢您花时间阅读本文。
Have any of you seen the simulator bong apps in android? How would you make that app? For example I have tried doing it using xml layouts. I divided the picture up and placed it in order and in segments so that when a particular picture is pressed a function will occur. Problem is that on different phones the size of the collective pictures either extends off the screen or is compressed.
I have also tried using surfaceViews with bitmaps so that each individual picture can take the size of the screen and adjust them accordingly. I am having trouble making the pictures not plop on top of eachother and instead be placed in order going down the screen. I can get the first 2 just fine designating the Rect dst with the starting height being where the other ended but the third and fourth aren't showing up on the screen. For example I used
Rect dst = new Rect(0, 0, mWidth, mHeight/7 );
For the first image which is on the top. Then for the second image
Rect dst = new Rect(0, mHeight/7, mWidth, mHeight/3 );
(mHeight and mWidth is the canvas width and height)
Not sure how to go about placing the next 2 pictures beneath them and eachother. I tried
Rect dst = new Rect(0, mHeight/7+(mHeight/3), mWidth, mHeight/7);
That didn't work though. It honestly looks really simple to do and I'm sure it is, but I just cant seem to get the images to work the way I want. Is there a way to leave the image as a whole and specify when a certain spot is selected it does something (that would work on every phone the same way).
Any help with this would be greatly appreciated. Any other ideas for how to get the result I want are also very much appreciated. Thanks for taking time to read this at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以将屏幕划分为左、上、宽、高等区域。
例如。
区域 1 (0,50,100,100)
区域 2 (100,50,100,100)。
并添加一个 OnTouchListener 并使用它来获取触摸坐标并检查它属于哪个区域。我不确定这是否是一个好方法,但它是可行的。
Well you could divide the screen into regions like left,top,width,height.
Eg.
Region 1 (0,50,100,100)
Region 2 (100,50,100,100).
And add a OnTouchListener and use that to get touch coords and check which region it belongs to. I'm not sure if it a good way but it is doable.