本文实例为大家分享了AndroID猜拳小游戏,供大家参考,具体内容如下
简单的 页面跳转 和 点击事件 的实现...
--> AndroIDManifest.xml
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.dragon.androID.fight" androID:versionCode="1" androID:versionname="1.0" > <uses-sdk androID:minSdkVersion="15" androID:targetSdkVersion="19" /> <application androID:allowBackup="true" androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" androID:theme="@style/Apptheme" > <activity androID:name="com.dragon.androID.fight.MainActivity" androID:label="@string/app_name" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name="com.dragon.androID.fight.OtherActivity"> </activity> </application></manifest>AndroIDManifest
--> strings.xml
<?xml version="1.0" enCoding="utf-8"?><resources> <string name="app_name">fight</string> <string name="hello_world">Hello World!</string> <string name="action_settings">Settings</string> <string name="player1">甲方</string> <string name="player2">乙方</string> <string name="choose1">石头</string> <string name="choose2">剪刀</string> <string name="choose3">布</string> <string name="sure">出拳</string> <string name="again">再来一局</string></resources>--> fragment_main.xml<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="#ffffff" tools:context="com.dragon.androID.fight.MainActivity$PlaceholderFragment" > <TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParenttop="true" androID:layout_centerHorizontal="true" androID:layout_margintop="36dp" androID:text="@string/player1" androID:textSize="30sp" /> <RadioGroup androID:ID="@+ID/radioGroup1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerHorizontal="true" androID:layout_centerVertical="true" > <Radiobutton androID:ID="@+ID/radio0" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:checked="true" androID:text="@string/choose1" /> <Radiobutton androID:ID="@+ID/radio1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="@string/choose2" /> <Radiobutton androID:ID="@+ID/radio2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="@string/choose3" /> </RadioGroup> <button androID:ID="@+ID/button1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignleft="@+ID/radioGroup1" androID:layout_below="@+ID/radioGroup1" androID:layout_margintop="14dp" androID:text="@string/sure" /> <ImageVIEw androID:ID="@+ID/imageVIEw1" androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:layout_above="@+ID/radioGroup1" androID:layout_below="@+ID/textVIEw1" androID:layout_centerHorizontal="true" androID:src="@drawable/b" /></relativeLayout>
--> activity_other.xml
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" androID:background="#ffffff" > <TextVIEw androID:ID="@+ID/textVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParenttop="true" androID:layout_centerHorizontal="true" androID:layout_margintop="36dp" androID:text="@string/player2" androID:textSize="30sp" /> <RadioGroup androID:ID="@+ID/radioGroup1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerHorizontal="true" androID:layout_centerVertical="true" > <Radiobutton androID:ID="@+ID/radio0" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:checked="true" androID:text="@string/choose1" /> <Radiobutton androID:ID="@+ID/radio1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="@string/choose2" /> <Radiobutton androID:ID="@+ID/radio2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="@string/choose3" /> </RadioGroup> <button androID:ID="@+ID/button1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignleft="@+ID/radioGroup1" androID:layout_below="@+ID/radioGroup1" androID:layout_margintop="14dp" androID:text="@string/sure" /> <TextVIEw androID:ID="@+ID/textVIEw2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignleft="@+ID/textVIEw1" androID:layout_below="@+ID/button1" androID:visibility="invisible" androID:layout_margintop="14dp"/> <button androID:ID="@+ID/button2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_below="@+ID/textVIEw2" androID:layout_centerHorizontal="true" androID:visibility="invisible" androID:text="@string/again" /> <ImageVIEw androID:ID="@+ID/imageVIEw1" androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:layout_above="@+ID/radioGroup1" androID:layout_below="@+ID/textVIEw1" androID:layout_centerHorizontal="true" androID:src="@drawable/a" /> </relativeLayout>
--> MainActivity
package com.dragon.androID.fight;import androID.app.Activity;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;import androID.Widget.ImageVIEw;import androID.Widget.Radiobutton;import androID.Widget.RadioGroup;public class MainActivity extends Activity { // 设置一个静态变量,用于关闭Activity public static MainActivity instance = null; private RadioGroup radioGroup1; private button button1; private ImageVIEw imageVIEw1; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { // 代表当前的Activity instance = this; super.onCreate(savedInstanceState); setContentVIEw(R.layout.fragment_main); radioGroup1 = (RadioGroup) findVIEwByID(R.ID.radioGroup1); // 设置图片透明 // imageVIEw1 = (ImageVIEw) findVIEwByID(R.ID.imageVIEw1); // imageVIEw1.getBackground().setAlpha(100); button1 = (button) findVIEwByID(R.ID.button1); button1.setonClickListener(new MybuttonListener()); } class MybuttonListener implements OnClickListener { @OverrIDe public voID onClick(VIEw v) { // 得到选中的Radiobutton Radiobutton radiobutton = (Radiobutton) findVIEwByID(radioGroup1 .getCheckedRadiobuttonID()); String radioText = radiobutton.getText().toString(); Intent intent = new Intent(); intent.putExtra("checked",radioText); intent.setClass(MainActivity.this,OtherActivity.class); startActivity(intent); } }}
--> OtherActivity
package com.dragon.androID.fight;import androID.app.Activity;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;import androID.Widget.Radiobutton;import androID.Widget.RadioGroup;import androID.Widget.TextVIEw;public class OtherActivity extends Activity { private RadioGroup radioGroup1; private button button1; private TextVIEw textVIEw2; private Radiobutton radiobutton; private button button2; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_other); radioGroup1 = (RadioGroup) findVIEwByID(R.ID.radioGroup1); button1 = (button) findVIEwByID(R.ID.button1); textVIEw2 = (TextVIEw) findVIEwByID(R.ID.textVIEw2); button2 = (button) findVIEwByID(R.ID.button2); button1.setonClickListener(new MybuttonListener()); button2.setonClickListener(new MybuttonListener1()); } class MybuttonListener implements OnClickListener { @OverrIDe public voID onClick(VIEw v) { radiobutton = (Radiobutton) findVIEwByID(radioGroup1 .getCheckedRadiobuttonID()); String buttonText = radiobutton.getText().toString(); Intent intent = getIntent(); String checked = intent.getStringExtra("checked"); // 设置VIEw为可见 textVIEw2.setVisibility(VIEw.VISIBLE); button2.setVisibility(VIEw.VISIBLE); String msg = "甲出:" + checked + "\n" + "乙出:" + buttonText + "\n"; if (buttonText.equals(checked)) { textVIEw2.setText(msg + "平局"); } if (buttonText.equals("石头")) { if (checked.equals("剪刀")) { textVIEw2.setText(msg + "乙方赢"); } else if (checked.equals("布")) { textVIEw2.setText(msg + "甲方赢"); } } if (buttonText.equals("剪刀")) { if (checked.equals("布")) { textVIEw2.setText(msg + "乙方赢"); } else if (checked.equals("石头")) { textVIEw2.setText(msg + "甲方赢"); } } if (buttonText.equals("布")) { if (checked.equals("石头")) { textVIEw2.setText(msg + "乙方赢"); } else if (checked.equals("剪刀")) { textVIEw2.setText(msg + "甲方赢"); } } } } class MybuttonListener1 implements OnClickListener { @OverrIDe public voID onClick(VIEw arg0) { Intent intent = new Intent(); intent.setClass(OtherActivity.this,MainActivity.class); finish(); // 关闭指定Activity MainActivity.instance.finish(); startActivity(intent); } }}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的最常见的猜拳小游戏Android代码实现全部内容,希望文章能够帮你解决最常见的猜拳小游戏Android代码实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)