Android - imageView 可以在屏幕上 float 吗?

标签 android view imageview

我有一个简短的问题。我目前使用的位图绘制在屏幕上的动态移动对象上方,当用户单击它们时,我使用一些自定义代码打开带有已注册 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/

相关文章:

Android Studio 构建失败

android - Android-无法解释的崩溃

java - ImageView 中的 gif 持续时间更长

android - RelativeView 中的 ImageView 导致崩溃?

android - 如何将移动应用程序扩展为电视应用程序(android)?

php - 插入mysql表,但是为什么json_encode返回null?

Android:从 View 中返回一个字符串?

android - forceLayout() 在 Android 中是如何工作的

mysql - MySQL 中的时间旅行 View

android - 指定 Android 库版本代码/名称