Skip to content

Commit

Permalink
Merge pull request #865 from chenweijia104/master
Browse files Browse the repository at this point in the history
#540 #91~#95 实验5-9
  • Loading branch information
zengsn committed Jun 1, 2016
2 parents 0aa852d + 0202145 commit 5f41ee3
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package net1314080903106.homeworks.androidworks.hzuapps.edu.net1314080903106;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Net1314080903106MainActivity extends AppCompatActivity {
int[] imageIds = new int[] { R.drawable.net1314080903106shoe_ok, R.drawable.net1314080903106shoe_sorry,
R.drawable.net1314080903106shoe_sorry};
private ImageView image1; //ImageView组件1
private ImageView image2; //ImageView组件2
private ImageView image3; //ImageView组件3
private TextView result;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1314080903106_main);//设置显示界面
image1 = (ImageView) findViewById(R.id.imageView1);
image2 = (ImageView) findViewById(R.id.imageView2);
image3 = (ImageView) findViewById(R.id.imageView3);
result = (TextView) findViewById(R.id.textView1);
reset();//随机
image1.setOnClickListener(new View.OnClickListener(){

public void onClick(View v) {

isRight(v, 0);
}
});
image2.setOnClickListener(new View.OnClickListener(){

public void onClick(View v) {

isRight(v, 1);
}
});
image3.setOnClickListener(new View.OnClickListener(){

public void onClick(View v) {
isRight(v, 2);
}
});
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
reset();
result.setText(R.string.title);
image1.setAlpha(255);
image2.setAlpha(255);
image3.setAlpha(255);
image1.setImageDrawable(getResources().getDrawable(
R.drawable.net1314080903106shoe_default));
image2.setImageDrawable(getResources().getDrawable(
R.drawable.net1314080903106shoe_default));
image3.setImageDrawable(getResources().getDrawable(
R.drawable.net1314080903106shoe_default));
}

});
}

protected void isRight(View v, int index) {

image1.setImageDrawable(getResources().getDrawable(imageIds[0]));//显示结果
image2.setImageDrawable(getResources().getDrawable(imageIds[1]));
image3.setImageDrawable(getResources().getDrawable(imageIds[2]));
image1.setAlpha(100);
image2.setAlpha(100);
image3.setAlpha(100);
ImageView v1 = (ImageView) v;
v1.setAlpha(255);
if (imageIds[index] == R.drawable.net1314080903106shoe_ok){
result.setText("恭喜您,猜对了,祝你幸福!");
} else {
result.setText("很抱歉,猜错了,要不要再试一次?");
}
}

private void reset() {

for (int i = 0; i < 3; i++) {
int temp = imageIds[i]; //将数组元素i保存到临时变量中
int index = (int) (Math.random() * 2); //生成一个随机数0 or 1
imageIds[i] = imageIds[index]; //将随机数指定的数组元素的内容赋值给数组元素i
imageIds[index] = temp;
}
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions app/src/main/res/layout/activity_net1314080903106_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/net1314080903106background"
android:id="@+id/tableLayout1" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="2"
android:id="@+id/tableRow1">
<TextView
android:id="@+id/textView1"
android:padding="10px"
android:gravity="center"
android:textColor="#010D18"
android:textSize="35px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title" />

</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_weight="1"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/imageView3"
android:paddingLeft="30px"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/net1314080903106shoe_default" />

<ImageView
android:id="@+id/imageView2"
android:paddingLeft="30px"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/net1314080903106shoe_default" />

<ImageView
android:id="@+id/imageView1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="30px"
android:src="@drawable/net1314080903106shoe_default" />

</LinearLayout>
</TableRow>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<Button
android:id="@+id/button1"
android:textColor="#000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="再来一次" />

</LinearLayout>

</TableLayout>

0 comments on commit 5f41ee3

Please sign in to comment.