私はボタンを確定値にスケールする方法を知っていますが、ユーザーがタッチしている間、ボタンのサイズを時間ごとに増減する方法はありますか?このような 何か:Androidのスケールボタンon touch
Button myButton = (Button)findViewById(R.id.myButton);
myButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Some timer action here or is there a better way?
v.setScaleX(v.getScaleX() + 0.1f);
v.setScaleY(v.getScaleY() + 0.1f);
return true;
}
else if(event.getAction() == MotionEvent.ACTION_UP) {
v.setScaleX(1);
v.setScaleY(1);
return true;
}
return false;
}
});
その他のアイデア - 動作しません:
myButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
myButton.setScaleX(myButton.getScaleX() + 0.1f);
myButton.setScaleY(myButton.getScaleY() + 0.1f);
}
};
while(event.getAction() != MotionEvent.ACTION_UP){ //Seems to be an infinite loop
timer.schedule(timerTask, 100);
}
}
else if(event.getAction() == MotionEvent.ACTION_UP) {
v.setScaleX(1);
v.setScaleY(1);
}
return false;
}
});
をし、XML(描画可能とアニメーション)で全体のことを行う方法はありますか?
[ここ](http://www.tutorialspoint.com/android/android_animations.htmは)非常に良い例です。あなたが達成しようとしているもののために。チュートリアルの画像ビューではなく、ボタンをアニメートすることができます。 – chejaras