Android:如何同时缩放多个视图?
我试图将图形分层,就像背景上的图标一样,第二层(图标)与第一层(背景)的左上角有一定的像素偏移。由于每个层最终都会有自己的动画,因此我将每个层放置在自己的视图中。
对于我的实现,我有两个 ImageView,每一层一个,位于relativelayout 内,而它又位于scrollview 内。 ImageView 使用相对于左上角 (0,0) 的layout_margin 进行定位。第一个 ImageView 比屏幕(背景)大,而第二个 ImageView 比屏幕(图标)小。 ScrollView 会自动调整第一个 ImageView(背景)的大小,因为它比屏幕大,但不会调整第二个 ImageView 的大小,因为它较小(图标)。
我需要它们一起缩放,并且我还需要第二层在第一层上的定位以相应地调整自身。这实际上在图层列表中效果很好,但由于动画,我被迫使用视图。我如何缩放和定位多个视图在一起,或者我是否需要为看起来应该相当基本的东西构建自己的类?
提前致谢。
I'm trying to layer graphics one top of each other, like an icon over a background, with the second layer (icon) at a certain pixel offset from the top left corner of first layer (background). Since each layer will eventually have its own animation, I'm placing each in its own View.
For my implementation I have two ImageViews, one for each layer, inside a RelativeLayout, which in turn is inside a ScrollView. ImageViews are positioned using layout_margin relative to the top left corner (0,0). The first ImageView is larger than the screen (background), while the second ImageView is smaller than it (icon). ScrollView automatically resizes the first ImageView (background) since it is larger than the screen, it does not resize the second since it is smaller (icon).
I need both of them to scale together, and I also need the positioning of the second layer over the first layer to adjust itself accordingly. This actually works well in a layer-list, but due to the animations I am forced to use Views. How can I scale and position multiple Views together, or do I need to build my own class for something that seems like it should be fairly basic?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在我的 Android 应用程序中遇到了类似的问题。 Android 引入了一组新的 API 来帮助我们解决此问题,setScaleX() 和 setScaleY()。
只需调用layout.getParent().setScaleX();和layout.getParent().setScaleY();
I had a similar problem in my android application. Android has introduced new set of API's to help us on this, setScaleX() and setScaleY().
Just call layout.getParent().setScaleX(); and layout.getParent().setScaleY();