Animaçao ao tocar na tela?

6 respostas
R

E o seguinte eu tentei fazer varios exemplos na net usando o drawableanimation mas não deu certo…não sei porque…
alguem sabe como fazer.
eu so quero tocar na tela e executar uma animação…
Valeu…

6 Respostas

M

mais informações assim fica dificil

R
package com.anime.animacao;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;

public class AnimationActivity extends Activity {
  
        
	AnimationDrawable rocketanimation;

	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	 
Aqui Activity.java
 


setContentView(R.layout.main);

	  ImageView image = (ImageView) findViewById(R.id.image);
	  image.setBackgroundResource(R.drawable.rocket_thrust1);
	  rocketanimation = (AnimationDrawable) image.getBackground();
	}

	public boolean onTouchEvent(MotionEvent event) {
	  if (event.getAction() == MotionEvent.ACTION_DOWN) {
	    rocketanimation.start();
	    return true;
	  }
	  return super.onTouchEvent(event);
	}
}
R

Dentro da pasta drawable carregguei as imagens

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true">
    <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>
R

Aqui esta o Arquivo Main xml...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/rocket_thrust1" />

</LinearLayout>
R

O problema que exexuta o arquivo sem problemas e diz que ja foi instalado no aparelho mas não acho ele de jeito nenhum…

R

Eu consegui instalar mas esta dando uma mensagen de erro dizendo me MInha aplicaçao parou sem explicaçao..
(stopped Unexpectedly)

Eu acho que e no manifest Mais nao sei Porque

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.anime.animacao"
    android:versionCode="1"
    android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="8" />

    <application  android:icon="@drawable/ic_launcher" android:label="@string/app_name">
        <activity android:name=".AnimationActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    

</manifest>

</manifest>
Criado 14 de junho de 2012
Ultima resposta 17 de jun. de 2012
Respostas 6
Participantes 2