简体   繁体   English

如何将buttonView从其原始位置移动到Android中的新位置?

[英]how to move a buttonView from its original position to the new position in Android?

我在(0,0)位置有一个按钮,当我单击该按钮时,应将其移到(-,x)位置,例如ex(-0,-2)位置,或(x,-y)位置,例如ex( 0,-2)位置。如何实现此逻辑。

you can use translate animation for that 您可以为此使用翻译动画

 Animation animation= AnimationUtils.loadAnimation( this, R.anim.animation);
 button.startAnimation( animation);

create amin folder in res and in amin folder create xml named as animation.xml res中创建一个amin文件夹,在amin文件夹中创建一个名为animation.xml的xml。

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
    android:fromXDelta="0"
    android:fromYDelta="0"
    android:toXDelta="-60"
    android:toYDelta="-30" />
</set> 

now you can play with translation 现在你可以玩翻译了

try this: 尝试这个:

        float fromX=0;
        float toX=0;
        float fromY=40;
        float toY=40;
        TranslateAnimation animation = new TranslateAnimation(fromX, toX, fromY, toY);
        animation.setDuration(300);
        animation.setFillAfter(true);
        yourView.startAnimation(animation);

If u use Android 3.0+ 如果您使用Android 3.0+

ObjectAnimator animation = ObjectAnimator.ofFloat(yourButton, "x", newX);
animation.setDuration(animTime); //In milliseconds
animation.start();

if u dont use Android 3.0+ u cant use the library: http://nineoldandroids.com/ to backport this funcionality. 如果您不使用Android 3.0+,则不能使用该库: http ://nineoldandroids.com/反向移植此功能。

cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将图像移动到Android中的原始位置? - How to move image to its original position in android? Sherlock中的子菜单从原来的位置跳到错误的位置 - sub menu in Sherlock is jumping from its original position to wrong position 如何将listview设置为其原始位置? - How to set listview to its original position? 如何(何时)将Android中的AlertDialog移动到屏幕上的新位置? - How (and when) to move AlertDialog in Android to a new position on the screen? 动画按钮移动并在Android中设置新位置 - Animate button move and set new position in Android 获取MotionEvent在ButtonView中的相对位置 - Getting relative position of a MotionEvent inside a buttonView Android动画:如何在不满足条件的情况下用手指平滑地移动视图并移动到其初始位置 - Android Animation: How to move a view smoothly along with finger and move to its initial position if condition is not satisfied 刷新时,Android自定义视图会移回原始位置 - Android Custom View move back to original position when refreshing Android ItemTouchHelper onChildDraw 使 itemView 回到原来的位置 - Android ItemTouchHelper onChildDraw make itemView return to its original position 在我的Android应用程序中,如何移动图像的位置? - In my Android app,how do I move the images from their position?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM