第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

一個簡單的猜拳游戲

一個簡單的猜拳游戲

Ma峰 2016-10-14 21:34:27
只是一個簡單的猜拳游戲,原來用普通Button沒問題,但是換了ImageButton加了圖片以后就崩潰了,是不是因為圖片的問題?package com.example.caiquan;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 MainActivity extends AppCompatActivity { ? ?@Override ? ?protected void onCreate(Bundle savedInstanceState) { ? ? ? ?super.onCreate(savedInstanceState); ? ? ? ?setContentView(R.layout.activity_main); ? ? ? ?init(); ? ?} ? ?private TextView result; ? ?private ImageView computer; ? ?private Button quan; ? ?private Button jiandao; ? ?private Button bu; ? ?private void init() { ? ? ? ?quan = (Button) findViewById(R.id.quan); ? ? ? ?jiandao = (Button) findViewById(R.id.jiandao); ? ? ? ?bu = (Button) findViewById(R.id.bu); ? ? ? ?result = (TextView) findViewById(R.id.result); ? ? ? ?computer = (ImageView) findViewById(R.id.imageview); ? ? ? ?quan.setOnClickListener(chuquan); ? ? ? ?jiandao.setOnClickListener(chujiandao); ? ? ? ?bu.setOnClickListener(chubu); ? ?} ? ?private Button.OnClickListener chuquan =new View.OnClickListener() { ? ? ? ?@Override ? ? ? ?public void onClick(View view) { ? ? ? ? ? ?//隨機數(shù)決定計算機出拳 ? ? ? ? ? ?int icom = (int) (Math.random()*3+1); ? ? ? ? ? ?//1--拳 ?2--剪刀 ?3--布 ? ? ? ? ? ?if (icom==1){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.stone); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.draw)); ? ? ? ? ? ?} ? ? ? ? ? ?if (icom==2){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.jiandao); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.win)); ? ? ? ? ? ?} ? ? ? ? ? ?if (icom==3){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.bu); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.lose)); ? ? ? ? ? ?} ? ? ? ?} ? ?}; ? ?private Button.OnClickListener chujiandao =new View.OnClickListener() { ? ? ? ?@Override ? ? ? ?public void onClick(View view) { ? ? ? ? ? ?//隨機數(shù)決定計算機出拳 ? ? ? ? ? ?int icom = (int) (Math.random()*3+1); ? ? ? ? ? ?//1--拳 ?2--剪刀 ?3--布 ? ? ? ? ? ?if (icom==1){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.stone); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.lose)); ? ? ? ? ? ?} ? ? ? ? ? ?if (icom==2){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.jiandao); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.draw)); ? ? ? ? ? ?} ? ? ? ? ? ?if (icom==3){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.bu); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.win)); ? ? ? ? ? ?} ? ? ? ?} ? ?}; ? ?private Button.OnClickListener chubu =new View.OnClickListener() { ? ? ? ?@Override ? ? ? ?public void onClick(View view) { ? ? ? ? ? ?//隨機數(shù)決定計算機出拳 ? ? ? ? ? ?int icom = (int) (Math.random()*3+1); ? ? ? ? ? ?//1--拳 ?2--剪刀 ?3--布 ? ? ? ? ? ?if (icom==1){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.stone); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.win)); ? ? ? ? ? ?} ? ? ? ? ? ?if (icom==2){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.jiandao); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.lose)); ? ? ? ? ? ?} ? ? ? ? ? ?if (icom==3){ ? ? ? ? ? ? ? ?computer.setImageResource(R.mipmap.bu); ? ? ? ? ? ? ? ?result.setText(getText(R.string.panduan)+getString(R.string.draw)); ? ? ? ? ? ?} ? ? ? ?} ? ?};}
查看完整描述

1 回答

已采納
?
ziom

TA貢獻948條經(jīng)驗 獲得超1109個贊

有可能圖片太大的問題,換成小圖試試

查看完整回答
1 反對 回復 2016-10-15
  • 1 回答
  • 1 關(guān)注
  • 1813 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號