Button Animieren

A

Anubiss

Neues Mitglied
0
Moin Leute. Folgendes Problem:

Ich habe mir ein Buch zur Android-Programmierung gekauft und nun besteht meine Aufgabe einen Button, der zur Game-Activity führt zu animieren, wenn der Button 10 Sekunden lang nicht gedrückt wurde. Eigentlich dachte ich, es wäre alles korrekt, aber der Button wackelt nicht.

buttonID = button1

res/anim/wackeln.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
          android:fromDegrees="-40"
          android:toDegrees="40"
          android:duration="1000"
          android:repeatCount="20" />

und in der main activity:
Code:
private Animation animationWackeln;
private Button startButton;
private Handler handler = new Handler();


public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(this);
        animationWackeln = AnimationUtils.loadAnimation(this, R.anim.wackeln);
        startButton = (Button)findViewById(R.id.button1);  
    }


private class WackleButton implements Runnable {

public void run() {
startButton.startAnimation(animationWackeln);
}
}

@Override

protected void onResume(){
super.onResume();
handler.postDelayed(new WackleButton(), 1000*10);
}

Bitte helft mir ^^
 
Ich hab vor längerer Zeit auch mal damit rumgespielt, mein Code sah am Ende so aus:

Code:
        LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(this, R.anim.layout_anim);
//      final ViewGroup layoutGroup = (ViewGroup)findViewById(R.id.layout_button_id);
        final ViewGroup layoutGroup = (ViewGroup)findViewById(R.id.main_layout_id);
        layoutGroup.setLayoutAnimation(controller);

.
.
.
.
        layoutGroup.startLayoutAnimation();

und die XMLs:
Code:
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="10%"
        android:animation="@anim/translate_anim" 
/>

Code:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
	android:fromXDelta="0%p"
	android:toXDelta="30%p"
	android:fromYDelta="0%p"
	android:toYDelta="30%p"
	android:interpolator="@android:anim/linear_interpolator"
	android:duration="3000"
/>

Ich glaub mich zu erinnern, daß ich auch zuerst wie du die Animation direkt auf den Button legen wollte, aber das hat nicht geklappt. Vielleicht hilft dir das ja weiter :)


Gruß Tom
 
Muss der obere Teil deines Codes in die OnCreate-Methode?
Ich bekomme leider einen Absturz, beim Ausführen.

Warum funktioniert denn die Möglichkeit nicht, die ich in meinem Buch vorgestellt bekam. Liegt es an der Android Version?
 

Ähnliche Themen

A
  • AnimaAngelo85
Antworten
1
Aufrufe
337
swa00
swa00
MES
Antworten
10
Aufrufe
820
MES
MES
C
Antworten
8
Aufrufe
1.127
swa00
swa00
Zurück
Oben Unten