老规矩。右键取得显示不出来的图片地址,利用下载工具下载这个图片。后缀改为rar即可得到源代码项目。
package zhang.game;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class hongtaoA extends Activity {
private ImageView mimageView01;
private ImageView mimageView02;
private ImageView mimageView03;
private Button mButton;
private TextView mText;
private int[] s1={R.drawable.p01,R.drawable.p02,R.drawable.p03};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mimageView01=(ImageView)findViewById(R.id.mImage01);
mimageView02=(ImageView)findViewById(R.id.mImage02);
mimageView03=(ImageView)findViewById(R.id.mImage03);
mButton =(Button)findViewById(R.id.mButton);
mText=(TextView)findViewById(R.id.mText);
mimageView01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mimageView01.setImageDrawable(getResources().getDrawable(s1[0]));
mimageView02.setImageDrawable(getResources().getDrawable(s1[1]));
mimageView03.setImageDrawable(getResources().getDrawable(s1[2]));
mimageView03.setAlpha(100);
mimageView02.setAlpha(100);
// TODO Auto-generated method stub
if(s1[0]==R.drawable.p01){
mText.setText(" ok");
}else{
mText.setText("error");
}
}
});
mimageView02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mimageView01.setImageDrawable(getResources().getDrawable(s1[0]));
mimageView02.setImageDrawable(getResources().getDrawable(s1[1]));
mimageView03.setImageDrawable(getResources().getDrawable(s1[2]));
mimageView03.setAlpha(100);
mimageView01.setAlpha(100);
// TODO Auto-generated method stub
if(s1[1]==R.drawable.p01){
mText.setText(" ok");
}else{
mText.setText("error");
}
}
});
mimageView03.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mimageView01.setImageDrawable(getResources().getDrawable(s1[0]));
mimageView02.setImageDrawable(getResources().getDrawable(s1[1]));
mimageView03.setImageDrawable(getResources().getDrawable(s1[2]));
mimageView01.setAlpha(100);
mimageView02.setAlpha(100);
// TODO Auto-generated method stub
if(s1[2]==R.drawable.p01){
mText.setText(" ok");
}else{
mText.setText("error");
}
}
});
mButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mText.setText(R.string.str_title);
mimageView01.setImageDrawable(getResources().getDrawable(R.drawable.p04));
mimageView02.setImageDrawable(getResources().getDrawable(R.drawable.p04));
mimageView03.setImageDrawable(getResources().getDrawable(R.drawable.p04));
mimageView01.setAlpha(255);
mimageView02.setAlpha(255);
mimageView03.setAlpha(255);
randon();
}});
}
private void randon(){
for(int i=0;i<3;i++){
int tmp=s1[i];
int s=(int)(Math.random()*2);
s1[i]=s1[s];
s1[s]=tmp;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/mText"
android:layout_width="270px"
android:layout_height="40px"
android:text="@string/str_title"
android:textSize="18sp"
android:layout_x="20px"
android:layout_y="32px"
>
</TextView>
<ImageView
android:id="@+id/mImage01"
android:layout_width="71px"
android:layout_height="96px"
android:layout_x="20px"
android:layout_y="122px"
android:src="@drawable/p04"
>
</ImageView>
<ImageView
android:id="@+id/mImage02"
android:layout_width="71px"
android:layout_height="96px"
android:layout_x="126px"
android:layout_y="122px"
android:src="@drawable/p04"
>
</ImageView>
<ImageView
android:id="@+id/mImage03"
android:layout_width="71px"
android:layout_height="96px"
android:layout_x="232px"
android:layout_y="122px"
android:src="@drawable/p04"
>
</ImageView>
<Button
android:id="@+id/mButton"
android:layout_width="118px"
android:layout_height="wrap_content"
android:text="@string/str_button"
android:layout_x="100px"
android:layout_y="302px"
>
</Button>
</AbsoluteLayout>