1

こんにちは、私はこのサイトに不慣れですが、しばらく潜んでいました。プログラミング初心者。

私の問題は、ボタンを押して、そのボタンが一定時間画像を表示した後、元の状態に戻ることです。これまでのところ、ボタンを画像に変更/遷移させることはできますが、ボタンに戻ることはありません。または、画像なしで前後に遷移させることもできます。

他のボタンは無視して、今のところ Button1 で試してみてください。前もって感謝します。

私のコードは次のとおりです。

public class MainActivity extends Activity implements OnClickListener {

    private Button Button1, Button2, Button3, Button4,
                   Button5, Button6, Button7, Button8,
                   Button9, Button10, Button11, Button12;

    private Button ButtonNewGame;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Declaring Buttons/Squares
        Button1 = (Button) findViewById(R.id.Button1);
        Button2 = (Button) findViewById(R.id.Button2);
        Button3 = (Button) findViewById(R.id.Button3);
        Button4 = (Button) findViewById(R.id.Button4);
        Button5 = (Button) findViewById(R.id.Button5);
        Button6 = (Button) findViewById(R.id.Button6);
        Button7 = (Button) findViewById(R.id.Button7);
        Button8 = (Button) findViewById(R.id.Button8);
        Button9 = (Button) findViewById(R.id.Button9);
        Button10 = (Button) findViewById(R.id.Button10);
        Button11= (Button) findViewById(R.id.Button11);
        Button12 = (Button) findViewById(R.id.Button12);
        //Declaring NewGame Button
        ButtonNewGame = (Button) findViewById(R.id.ButtonNewGame);

        //Adding OnClickListeners
        Button1.setOnClickListener(this);
        Button2.setOnClickListener(this);
        Button3.setOnClickListener(this);
        Button4.setOnClickListener(this);
        Button5.setOnClickListener(this);
        Button6.setOnClickListener(this);
        Button7.setOnClickListener(this);
        Button8.setOnClickListener(this);
        Button9.setOnClickListener(this);
        Button10.setOnClickListener(this);
        Button11.setOnClickListener(this);
        Button12.setOnClickListener(this);

        ButtonNewGame.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        //Button1.setBackgroundResource(R.drawable.ic_launcher);
        Animation animation = new AlphaAnimation(1, 0);
        animation.setDuration(1000);
        animation.setInterpolator( new LinearInterpolator());
        animation.setRepeatCount(Animation.ABSOLUTE);
        animation.setRepeatMode(Animation.REVERSE);

        if(v == Button1){
            Button1.startAnimation(animation);
        }
    }
}
4

3 に答える 3

0

これはやり過ぎかもしれませんが、 をクリックすると開始する内部のCountDownTimerButtonを使用できます。Buttonイメージを変えるときもこれ。次に、CountDownTimers onFinish()で、の背景をButtonデフォルトの値に設定します

于 2013-05-29T00:23:20.620 に答える