【问题标题】:How to change button position in Transition animation如何在过渡动画中更改按钮位置
【发布时间】:2014-02-12 19:51:46
【问题描述】:

我正在开发屏幕,其中四个按钮从左到右水平移动,并且在每个按钮单击时我都必须打开 webView,所以任何人都可以建议如何更改按钮位置,以便检测到按钮的正确单击事件。

我已阅读:动画实际上不会移动按钮,而只会移动其图像。 那么添加按钮的正确方法是什么。

我是 stackoverflow 和 android 动画的新手,所以请建议....

setContentView(R.layout.activity_main);
     ll = (LinearLayout) findViewById(R.id.topbar);
     animation = AnimationUtils.loadAnimation(this, R.anim.animation_right);
     animation.setRepeatCount(TranslateAnimation.INFINITE);
     animation.setRepeatMode(TranslateAnimation.RESTART);
     animation.setAnimationListener(new SlidingButtonAnimationListener());
     animation.setDuration(30000);
    ll.startAnimation(animation);
    button1=(Button)findViewById(R.id.button1);
    button2=(Button)findViewById(R.id.button2);
    button3=(Button)findViewById(R.id.button3);
    button4=(Button)findViewById(R.id.button4);
    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button1 clicked");
        }
    });
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button2 clicked");
        }
    });
    button3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button3 clicked");
        }
    });
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button4 clicked");
        }
    });
}
private class SlidingButtonAnimationListener implements AnimationListener {

    public void onAnimationEnd(Animation animation){

    }

    public void onAnimationRepeat(Animation animation){}

    public void onAnimationStart(Animation animation){}

}

【问题讨论】:

    标签: android android-animation


    【解决方案1】:

    您需要使用 Object Animator 来移动对象。我找到了关于您的问题的 StackOverFlow 答案。 Here 是链接。那应该可以解决它。

    【讨论】:

    • 它可以工作,但你能建议在 objectanimator 中什么是 setFillAfter(true) 等价于背靠背动画。
    • 这是对您问题的很好解释之一。 Here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    相关资源
    最近更新 更多