darkhah1
پنج شنبه 21 خرداد 1394, 21:50 عصر
سلام من از یه image button برای لمس و صدا دادن دکمه خود استفاده کرده ام.
و می خوام به این دکمه هنگام لمس یه انیمیشنم رش اعمال بشه ولی هر کاری میکنم انیمیشن کار نمیکنه اینم کدم
package com.example.dd;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity implements OnTouchListener {
private MediaPlayer mp;
private Animation b;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageButton zero=(ImageButton) findViewById(R.id.imageButton1);
zero.setOnTouchListener(this);
mp = MediaPlayer.create(this, R.raw.closehh);
b=AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
b=AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
b.start();
mp = MediaPlayer.create(getApplicationContext(), R.raw.closehh);
mp.start();
mp.setLooping(true);
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp1) {
// TODO Auto-generated method stub
mp1.release();
}
});
Log.i("Action", "Down");
break;
case MotionEvent.ACTION_MOVE:
Log.i("Action", "Move");
Log.i("On Long", "On Long");
break;
case MotionEvent.ACTION_CANCEL:
mp.pause();
Log.i("Action", "Cancel");
break;
case MotionEvent.ACTION_UP:
mp.setLooping(false);
//mp1.stop();
Log.i("Action", "up");
break;
default:
break;
}
return true;
}
}
و می خوام به این دکمه هنگام لمس یه انیمیشنم رش اعمال بشه ولی هر کاری میکنم انیمیشن کار نمیکنه اینم کدم
package com.example.dd;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity implements OnTouchListener {
private MediaPlayer mp;
private Animation b;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageButton zero=(ImageButton) findViewById(R.id.imageButton1);
zero.setOnTouchListener(this);
mp = MediaPlayer.create(this, R.raw.closehh);
b=AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
b=AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
b.start();
mp = MediaPlayer.create(getApplicationContext(), R.raw.closehh);
mp.start();
mp.setLooping(true);
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp1) {
// TODO Auto-generated method stub
mp1.release();
}
});
Log.i("Action", "Down");
break;
case MotionEvent.ACTION_MOVE:
Log.i("Action", "Move");
Log.i("On Long", "On Long");
break;
case MotionEvent.ACTION_CANCEL:
mp.pause();
Log.i("Action", "Cancel");
break;
case MotionEvent.ACTION_UP:
mp.setLooping(false);
//mp1.stop();
Log.i("Action", "up");
break;
default:
break;
}
return true;
}
}