Android 淡入后的动画设置按钮不可单击
我只是想淡入我的应用程序中的图像按钮。但问题是,图像按钮正在淡入,但之后无法单击。这意味着在显示OnClick事件时,单击它们时不会启动它们。 是因为我将按钮的原始位置设置为layout_marginleft:-100dp; 有没有办法让它工作,即使我设置的利润率为-100dp? 你能告诉我为什么吗 以下是我的功能:Android 淡入后的动画设置按钮不可单击,android,user-interface,mobile,Android,User Interface,Mobile,我只是想淡入我的应用程序中的图像按钮。但问题是,图像按钮正在淡入,但之后无法单击。这意味着在显示OnClick事件时,单击它们时不会启动它们。 是因为我将按钮的原始位置设置为layout_marginleft:-100dp; 有没有办法让它工作,即使我设置的利润率为-100dp? 你能告诉我为什么吗 以下是我的功能: public void onclickMenu(View view) { final int menuOffsetTime = 4000; final Im
public void onclickMenu(View view) {
final int menuOffsetTime = 4000;
final ImageButton menuClose = (ImageButton) findViewById(R.id.menu_close);
final ImageButton menuOpen = (ImageButton) findViewById(R.id.menu_open);
final ImageButton expButton = (ImageButton) findViewById(R.id.export);
final ImageButton opButton = (ImageButton) findViewById(R.id.open);
final ImageButton setButton = (ImageButton) findViewById(R.id.settings);
final AnimationSet animationSetIn = new AnimationSet(false);
final AnimationSet animationSetOut = new AnimationSet(false);
Animation animationIn = AnimationUtils.loadAnimation(this, R.anim.menu_anim_in);
Animation animationOut = AnimationUtils.loadAnimation(this, R.anim.menu_anim_out);
expButton.clearAnimation();
opButton.clearAnimation();
setButton.clearAnimation();
if(animationIn != null && animationOut != null) {
animationSetIn.addAnimation(animationIn);
animationSetOut.addAnimation(animationOut);
animationSetIn.setInterpolator(new AccelerateDecelerateInterpolator());
animationSetOut.setInterpolator(new AccelerateDecelerateInterpolator());
if(view.getId() == R.id.menu_open) {
animationSetIn.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
animationSetOut.setStartOffset(menuOffsetTime);
animationSetOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {}
});
if(menuOpen.getVisibility() == View.INVISIBLE) {
opButton.startAnimation(animationSetOut);
setButton.startAnimation(animationSetOut);
if(export) {
expButton.startAnimation(animationSetOut);
}
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
menuClose.setVisibility(View.INVISIBLE);
menuOpen.setVisibility(View.VISIBLE);
}
}, menuOffsetTime);
}
}
});
opButton.startAnimation(animationSetIn);
setButton.startAnimation(animationSetIn);
opButton.setEnabled(true);
if(export) {
expButton.startAnimation(animationSetIn);
}
menuClose.setVisibility(View.VISIBLE);
menuOpen.setVisibility(View.INVISIBLE);
} else {
opButton.startAnimation(animationSetOut);
setButton.startAnimation(animationSetOut);
if(export) {
expButton.startAnimation(animationSetOut);
}
menuClose.setVisibility(View.INVISIBLE);
menuOpen.setVisibility(View.VISIBLE);
}
}
}
我在菜单中有这个动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate android:fromXDelta="0%" android:toXDelta="100%"
android:duration="2000" android:fillAfter="true" />
</set>
在我的菜单中,这是:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="false">
<translate android:fromXDelta="100%" android:toXDelta="0%"
android:duration="2000" android:fillAfter="true" />
</set>
这在我的布局文件中:
<ImageButton
android:layout_width="@dimen/menu_button_width"
android:layout_height="@dimen/menu_button_height"
android:id="@+id/export"
android:onClick="onclickExport"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="0dp"
android:layout_marginLeft="-100dp"
android:background="@drawable/export" />
<ImageButton
android:layout_width="@dimen/menu_button_width"
android:layout_height="@dimen/menu_button_height"
android:id="@+id/open"
android:onClick="onclickOpen"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="70dp"
android:layout_marginLeft="-100dp"
android:background="@drawable/open" />
<ImageButton
android:layout_width="@dimen/menu_button_width"
android:layout_height="@dimen/menu_button_height"
android:id="@+id/settings"
android:onClick="onclickSettings"
android:layout_gravity="left|center_vertical"
android:layout_marginTop="140dp"
android:layout_marginLeft="-100dp"
android:background="@drawable/settings" />
提前谢谢你 根据xml,onclickMenu方法未使用 没有一个ImageButton调用onclickmenu方法。那个么,你们认为这个方法是自己调用的吗 如果仍有问题,请将此添加到图像按钮 android:clickable=“true”
希望它会有所帮助通过另一个按钮调用该函数。。动画可以工作,所以这不是问题所在。问题是只有按钮图像被移动,而不是整个视图。。但我不知道是否有一些选项也移动容器,这是可点击的动画功能。我想我应该可以用setpadding来实现,但是当我像opButton.setpadding(100,0,0,0)那样尝试时;它不起作用。。