2012-03-03 87 views
2

工作后,我有一些关于它的按钮相对布局,我创建了一个旋转动画,旋转它按钮动作不旋转

但是当我将其旋转按钮的操作不能正常工作,行动按钮仍然保存按钮的老大地位旋转前

可以在任何一个请帮我解决这个

<ImageButton 
     android:id="@+id/last20" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="75dp" 
     android:background="@null" 
     android:src="@drawable/last20_selector" 
     android:onClick="last20OnClick"/> 

super.onCreate(savedInstanceState); 
    setContentView(R.layout.wheel); 

    RelativeLayout layout = (RelativeLayout) findViewById(R.id.wheelLayout); 

    RotateAnimation rotateAnim = new RotateAnimation(0, 45, 
      Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 
      0.5f); 

    rotateAnim.setDuration(1000); 
    rotateAnim.setRepeatCount(0); 
    rotateAnim.setFillAfter(true); 
    layout.startAnimation(rotateAnim); 
} 

public void last20OnClick(View view) { 
     System.out.println("last20OnClick"); 
    } 
+0

你必须分享一些代码...... – 2012-03-03 21:08:53

+0

你找到了解决办法吗?面对同样的问题。 – Beena 2014-11-27 05:07:49

+0

不,我没有找到解决方案,并使用画布构建我的控件并停止使用绝对布局。 – 2014-12-01 08:27:16

回答

0

在您的代码中,您是否设置了OnClickListener? 尝试把听众在你onCreate方法:

findViewById(R.id.last20).setOnClickListener(new OnClickListener() { 

    public abstract void onClick (View v) { 
     last20OnClick(v); 
    } 
}); 

希望它可以帮助你!

+0

'但是,不要将OnClickListener应用于您的活动中的按钮,您可以使用android:onClick属性为XML布局中的按钮指定一个方法。 'http://developer.android.com/reference/android/widget/Button.html – Selvin 2012-03-03 21:39:23

+0

是的,我已经将它设置在XML文件android:onClick – 2012-03-04 01:30:29

0

尝试设置属性:如建议在这question

rotateAnim.setFillAfter(false); 
rotateAnim.setFillBefore(false); 

android:fillAfter="false" 
android:fillBefore="false" 

或Java编写的。它帮助了我。 Aslo,保存您的动画从-45度旋转到0度。

+0

不,我不能这样做,因为我需要保持旋转 – 2012-03-04 01:31:15

+0

RotateAnimation rotateAnim = new RotateAnimation(-45,0,...);你有相同的旋转。 – Silver 2012-03-04 10:41:33