欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

最常見(jiàn)的猜拳小游戲Android代碼實(shí)現(xiàn)

 更新時(shí)間:2016年08月30日 09:17:44   作者:西門(mén)吃雪  
這篇文章主要為大家詳細(xì)介紹了最常見(jiàn)的猜拳小游戲Android代碼實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android猜拳小游戲,供大家參考,具體內(nèi)容如下

簡(jiǎn)單的 頁(yè)面跳轉(zhuǎn) 和 點(diǎn)擊事件 的實(shí)現(xiàn)...

--> 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">再來(lái)一局</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 {
 // 設(shè)置一個(gè)靜態(tài)變量,用于關(guān)閉Activity
 public static MainActivity instance = null;
 private RadioGroup radioGroup1;
 private Button button1;
 private ImageView imageView1;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 // 代表當(dāng)前的Activity
 instance = this;
 super.onCreate(savedInstanceState);
 setContentView(R.layout.fragment_main);
 radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
 // 設(shè)置圖片透明
 // 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");
  // 設(shè)置View為可見(jiàn)
  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();
  // 關(guān)閉指定Activity
  MainActivity.instance.finish();
  startActivity(intent);
 }
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android自定義實(shí)現(xiàn)日歷控件

    Android自定義實(shí)現(xiàn)日歷控件

    這篇文章主要為大家詳細(xì)介紹了Android自定義實(shí)現(xiàn)日歷控件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • android?原生安全音量配置邏輯設(shè)計(jì)詳解

    android?原生安全音量配置邏輯設(shè)計(jì)詳解

    這篇文章主要為大家介紹了android?原生安全音量配置邏輯設(shè)計(jì)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • Android學(xué)習(xí)之文件存儲(chǔ)讀取

    Android學(xué)習(xí)之文件存儲(chǔ)讀取

    本節(jié)給大家介紹的是Android數(shù)據(jù)存儲(chǔ)與訪(fǎng)問(wèn)方式中的一個(gè)——文件存儲(chǔ)與讀寫(xiě),當(dāng)然除了這種方式外,我們可以存到SharedPreference,數(shù)據(jù)庫(kù), 或者ContentProvider中,當(dāng)然這些后面都會(huì)講,嗯,開(kāi)始本文內(nèi)容~
    2016-07-07
  • Android開(kāi)發(fā)教程之如何屏蔽View的重復(fù)點(diǎn)擊

    Android開(kāi)發(fā)教程之如何屏蔽View的重復(fù)點(diǎn)擊

    這篇文章主要給大家介紹了關(guān)于Android開(kāi)發(fā)教程之如何屏蔽View的重復(fù)點(diǎn)擊的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • Android添加用戶(hù)組及自定義App權(quán)限的方法

    Android添加用戶(hù)組及自定義App權(quán)限的方法

    今天小編就為大家分享一篇Android添加用戶(hù)組及自定義App權(quán)限的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • Android自定義廣播接收

    Android自定義廣播接收

    這篇文章主要為大家詳細(xì)介紹了Android自定義廣播接收,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android的HTTP擴(kuò)展包OkHttp中的緩存功能使用方法解析

    Android的HTTP擴(kuò)展包OkHttp中的緩存功能使用方法解析

    OkHttp(GitHub主頁(yè)https://github.com/square/okhttp)是一款高人氣的第三方Android網(wǎng)絡(luò)編程包,這里我們來(lái)看一下Android的HTTP擴(kuò)展包OkHttp中的緩存功能使用方法解析:
    2016-07-07
  • Android 開(kāi)發(fā)訂單流程view實(shí)例詳解

    Android 開(kāi)發(fā)訂單流程view實(shí)例詳解

    這篇文章主要介紹了 Android 開(kāi)發(fā)訂單流程view實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android端TCP長(zhǎng)連接的性能優(yōu)化教程分享

    Android端TCP長(zhǎng)連接的性能優(yōu)化教程分享

    在開(kāi)發(fā)過(guò)程中,我們經(jīng)常會(huì)用到TCP/IP連接實(shí)現(xiàn)即時(shí)數(shù)據(jù)傳輸,下面這篇文章主要給大家介紹了關(guān)于Android端TCP長(zhǎng)連接的性能優(yōu)化的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2018-03-03
  • android獲取屏幕像素思路及代碼

    android獲取屏幕像素思路及代碼

    本文為大家詳細(xì)介紹下android是怎樣獲取屏幕像素的,感興趣的各位可以參考下哈,希望對(duì)你學(xué)習(xí)android有所幫助
    2013-04-04

最新評(píng)論