Imageactivity.java
package com.example.Imagebuttonactivity;
import android.os.Bundle; import android.app.Activity; import
android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class Imagebuttonactivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.imagebuttonactivity, menu);
return true;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set up main content view
setContentView(R.layout.activity_main);
configureImageButton();
}
private void configureImageButton() {
ImageButton btn = (ImageButton) findViewById(R.id. imageButton1);
btn.setOnClickListener (new View.OnClickListener(){
@Override
public void onClick(VIew v) {
// Change image on botton
ImageButton btn = (ImageButton) findViewById(R.id. imageView1);
btn.setImageResource(R.drawable.imageview4);
ImageButton btn = (ImageButton) findViewById(R.id. imageView2);
btn.setImageResource(R.drawable.imageview5);
ImageButton btn = (ImageButton) findViewById(R.id. imageView3);
btn.setImageResource(R.drawable.imageview6);
}
});
} }
答案 0 :(得分:0)
这些会发生得如此之快,以至于您只会看到最后一张图片。
使用某种延迟并使图像更新之间的按钮无效。
btn.invalidate():
查看CountDownTimer,您可以在onClick中启动它,然后在每个刻度上更改图像。