gpt4 book ai didi

android - 强制关闭ImageButton的onClick,无法弄清楚为什么

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:06:55 26 4
gpt4 key购买 nike

我正在尝试使用 ImageButtons 做一个简单的动画,当我设置它时,如果我只是触摸屏幕,它工作得很好,但如果我尝试在点击时做,应用程序就会关闭。

主.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<ImageButton
android:id="@+id/plus1"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@null"
android:src="@drawable/plus"
android:visibility="visible"
android:gravity="center_horizontal"
android:onClick="RunAnimations"
/>

<ImageButton
android:id="@+id/gears1"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="@null"
android:gravity="center_horizontal"
android:src="@drawable/gears"
android:textSize="42sp" />
</LinearLayout>

翻译.xml

<?xml version="1.0" encoding="utf-8"?>
<set>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="-100%"
android:toYDelta="0%"
android:duration="1000"
android:zAdjustment="top" >
</translate>

<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000">
</alpha>
</set>

主要 Activity :

    public class AnimationtestActivity extends Activity  {        /** Called when the activity is first created. */        @Override        public void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentView(R.layout.main);        }        private void RunAnimations() {            Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);            View ib = findViewById(R.id.gears1);            ib.clearAnimation();             ib.startAnimation(a);             }    }

edit:

I fixed the private void RunAnimations(View view)

But it's still force closing

edit 2: Contents of logcat

03-08 13:07:33.968: E/AndroidRuntime(29270): FATAL EXCEPTION: main
03-08 13:07:33.968: E/AndroidRuntime(29270): java.lang.IllegalStateException: Could not find a method RunAnimations(View) in the activity class com.test.AnimationtestActivity for onClick handler on view class android.widget.ImageButton with id 'plus1'
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.view.View$1.onClick(View.java:3026)
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.view.View.performClick(View.java:3480)
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.view.View$PerformClick.run(View.java:13983)
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.os.Handler.handleCallback(Handler.java:605)
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.os.Handler.dispatchMessage(Handler.java:92)
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.os.Looper.loop(Looper.java:137)
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-08 13:07:33.968: E/AndroidRuntime(29270): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 13:07:33.968: E/AndroidRuntime(29270): at java.lang.reflect.Method.invoke(Method.java:511)
03-08 13:07:33.968: E/AndroidRuntime(29270): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-08 13:07:33.968: E/AndroidRuntime(29270): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-08 13:07:33.968: E/AndroidRuntime(29270): at dalvik.system.NativeStart.main(Native Method)
03-08 13:07:33.968: E/AndroidRuntime(29270): Caused by: java.lang.NoSuchMethodException: RunAnimations [class android.view.View]
03-08 13:07:33.968: E/AndroidRuntime(29270): at java.lang.Class.getConstructorOrMethod(Class.java:460)
03-08 13:07:33.968: E/AndroidRuntime(29270): at java.lang.Class.getMethod(Class.java:915)
03-08 13:07:33.968: E/AndroidRuntime(29270): at android.view.View$1.onClick(View.java:3019)
03-08 13:07:33.968: E/AndroidRuntime(29270): ... 11 more

最佳答案

框架找不到您的点击处理程序方法,因为它的签名有误。像这样声明:

public void RunAnimations(View view) {
. . .
}

关于android - 强制关闭ImageButton的onClick,无法弄清楚为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9622446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com