2014-02-12 70 views
2

我正在开发屏幕,其中四个按钮从左向右水平移动,并且每个按钮单击我必须打开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){} 

} 

回答

0

您需要使用对象的动画移动的对象。我发现一个关于你的问题的StackOverFlow答案。 Here是链接。那应该解决它。

+0

它的工作原理,但你可以建议什么是setavillAfter(true)相当于objectanimator背对背动画。 – manish

+0

这是你的问题很好的解释之一。 [这里](http://stackoverflow.com/a/5888969/1080954) – osayilgan