이게 처음이고,
이게 마지막입니다. 이렇게 버튼을 꾹 누르면 게이지가 올라가고,
떼면 거기서 멈추는 게이지를 만들고 싶습니다.
일단 소소코드는 아래와 같이 입력했습니다. xml은 쉬운데, 액티비티쪽이 어렵네요.
터치리스너쪽에서 막힙니다.
package andromeda.android.button1;
import android.graphics.drawable.AnimationDrawable;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageView img;
Button start;
AnimationDrawable ani;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = findViewById(R.id.img);
start = findViewById(R.id.start);
img.setBackgroundResource(R.drawable.animation);
ani = (AnimationDrawable) img.getBackground();
start.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
img.setBackgroundResource( R.mipmap.a1 );
img.setBackgroundResource( R.mipmap.a2 );
img.setBackgroundResource( R.mipmap.a3 );
img.setBackgroundResource( R.mipmap.a4 );
img.setBackgroundResource( R.mipmap.a5 );
img.setBackgroundResource( R.mipmap.a6 );
img.setBackgroundResource( R.mipmap.a7 );
img.setBackgroundResource( R.mipmap.a8 );
img.setBackgroundResource( R.mipmap.a9 );
img.setBackgroundResource( R.mipmap.a10 );
break;
case MotionEvent.ACTION_UP:
ani.stop();
break;
}
return true;
}
});
}
}


