开发者

Android - can an imageView float around on the screen?

开发者 https://www.devze.com 2023-03-30 09:12 出处:网络
I have a quick question. Im currently using bitmaps that get drawn above a dynamic moving object on screen and when a user clicks them Im using some custom code to open a view with a registered onclic

I have a quick question. Im currently using bitmaps that get drawn above a dynamic moving object on screen and when a user clicks them Im using some custom code to open a view with a registered onclick. Instead of using the code we came up with I was wondering if its possible just to replace the bitmap with an imageView.

Will that work? or should I just stick it out and continue to build on the custom class Ive built. After looking at requirements it became apparent to me that an imageview would have all the built in functionality that I would need to do what I want. Or is there a better v开发者_C百科iew class that would work for a dynamically moving view on the screen that moves.


You could use animations for moving views.

example:

AnimationSet set = new AnimationSet(true);

Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);

animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
        -1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
        Animation.RELATIVE_TO_SELF, 0.0f,
        Animation.RELATIVE_TO_SELF, 0.0f);
animation.setDuration(1500);
set.addAnimation(animation);

LayoutAnimationController controller = new LayoutAnimationController(set, 0.25f);

yourView.setLayoutAnimation(controller);
controller.start();

Or in the custom view's onDraw, manipulate the canvas.

0

精彩评论

暂无评论...
验证码 换一张
取 消