我有一个简短的问题。我目前使用的位图绘制在屏幕上的动态移动对象上方,当用户单击它们时,我使用一些自定义代码打开带有已注册 onclick 的 View 。我没有使用我们想出的代码,而是想知道是否可以用 imageView 替换位图。
那行得通吗?或者我应该坚持下去并继续构建我构建的自定义类。在查看需求后,我很明显地发现 imageview 将具有我需要做我想做的事情的所有内置功能。或者是否有更好的 View 类适用于移动屏幕上的动态移动 View 。
最佳答案
你可以使用 animations用于移动 View 。
例子:
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();
或者在自定义view的onDraw中,操作canvas .
关于Android - imageView 可以在屏幕上 float 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7187299/