猜猜我在想什么(以及动画xml的设置)
来源:互联网 发布:centos中如何退出终端 编辑:程序博客网 时间:2024/05/01 02:02
java;
package EX04_24.txt;import EX04_24.txt.R.string;import android.R.integer;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.Button;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.RadioGroup.OnCheckedChangeListener;import android.widget.TextView;public class EX04_24 extends Activity {private TextView mTextView;private RadioGroup mRadioGroup;private RadioButton mRadioButton1;private RadioButton mRadioButton2;private RadioButton mRadioButton3;private Button mButton1;private Button mButton2;private int[] choices = null;private String[] items = null;private int mchoice;private int mCount = 0;private boolean mNotify = false;private String mStr = ""; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initApp(); }private void initApp() {// TODO Auto-generated method stubmTextView = (TextView)findViewById(R.id.TextView01);mRadioGroup = (RadioGroup)findViewById(R.id.RadioGroup01);mRadioButton1 = (RadioButton)findViewById(R.id.RadioButton01);mRadioButton2 = (RadioButton)findViewById(R.id.RadioButton02);mRadioButton3 = (RadioButton)findViewById(R.id.RadioButton03);mButton1 = (Button)findViewById(R.id.Button01);mButton2 = (Button)findViewById(R.id.Button02);choices = new int[] {mRadioButton1.getId(),mRadioButton2.getId(),mRadioButton3.getId() };items = new String[] {getResources().getString(R.string.app_choice1),getResources().getString(R.string.app_choice2),getResources().getString(R.string.app_choice3) };init_mchoice();mRadioGroup.setOnCheckedChangeListener(myChecked);mButton1.setOnClickListener(myAnswer);mButton2.setOnClickListener(myClear);}private void init_mchoice() {// TODO Auto-generated method stubmchoice = choices[(int) (Math.random()*3)];for (int i = 0; i < choices.length; i++) {if (mchoice == choices[i]) {mStr = items[i];break;}}}OnClickListener myClear =new Button.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubmTextView.setText(getResources().getString(R.string.str_hellow));mNotify = false;mRadioGroup.clearCheck();mCount = 0;init_mchoice();}};OnClickListener myAnswer =new Button.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif (mNotify) {mTextView.setText(getResources().getString(R.string.str_correct) + mStr);mNotify = false;mRadioGroup.clearCheck();mCount = 0;} else {mCount++;mTextView.setText(getResources().getString(R.string.str_error) + Integer.toString(mCount) + ")");Animation am = new AnimationUtils().loadAnimation(EX04_24.this, R.anim.my_anim);v.startAnimation(am);}init_mchoice();}};OnCheckedChangeListener myChecked = new RadioGroup.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubif (checkedId == mchoice) {mNotify = true;} else {mNotify = false;}}};}
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><TextViewandroid:id="@+id/TextView01" android:textSize = "18sp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/str_hellow" /><TextView android:text="@string/app_title" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView><RadioGroup android:id="@+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content"><RadioButton android:text="@string/app_choice1" android:id="@+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton><RadioButton android:text="@string/app_choice2" android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton><RadioButton android:text="@string/app_choice3" android:id="@+id/RadioButton03" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton></RadioGroup><LinearLayout android:id="@+id/LinearLayout01"android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"><Button android:text="回答" android:id="@+id/Button01"android:layout_marginLeft = "20dip" android:layout_width="100dip" android:layout_height="wrap_content"></Button><Button android:text="清除" android:id="@+id/Button02" android:layout_marginLeft = "50dip" android:layout_width="100dip" android:layout_height="wrap_content"></Button></LinearLayout></LinearLayout>
string.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?><resources> <string name="hello">Hello World, EX04_24!</string> <string name="app_name">EX04_24</string> <string name="str_hellow">欢迎进入猜猜我在想什么</string> <string name="str_correct">你猜对了,我在想:</string> <string name="str_error">猜错啦,再猜猜看...(</string> <string name="app_title">请用念力猜猜我现在在想什么?</string> <string name="app_choice1">忍者狂刀</string> <string name="app_choice2">最后一战:星河战役</string> <string name="app_choice3">吉他英雄:世界轮回乐队</string></resources>
my_anim.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="3000"/><scale android:interpolator= "@android:anim/accelerate_decelerate_interpolator"android:fromXScale = "0.0"android:toXScale = "1.4"android:fromYScale = "0.0"android:toYScale = "1.4"android:pivotX = "50%"android:pivotY = "50%"android:fillAfter = "false"android:duration = "7000"/><translate android:fromXDelta = "30"android:toXDelta = "-80"android:fromYDelta = "30"android:toYDelta = "300"android:duration = "5000"/><rotateandroid:interpolator= "@android:anim/accelerate_decelerate_interpolator"android:fromDegrees = "0"android:toDegrees = "+350"android:pivotX = "50%"android:pivotY = "50%"android:duration = "3000" /></set>
- 猜猜我在想什么(以及动画xml的设置)
- 猜猜我在想什么(RadioButtonID)
- 练习写C++代码(110)--让我猜猜你在想什么?
- 讓我看看你的唇,猜猜你在說什麼
- android动画中fillBefore以及fillAfter在xml中设置无效的问题
- python小游戏-猜猜我正在想的数字是多少?
- 猜猜打印的是幅什么图片?
- 猜猜结果是什么?
- 猜猜输出什么,为什么?
- 在XML中设置补间动画
- 一个简单的C++代码,你猜猜结果是什么?
- 让我猜猜结局
- 56 猜猜我是谁
- 猜猜谁是我
- 猜猜谁是我
- 猜猜谁是我
- 猜猜谁是我
- 当我debug的时候我在想些什么
- 图文并茂 在ML OS X 10.8 + XCode4.4/4.4.1下实现无证书真机调试IOS5.1.1(亲测,附调试截图)
- 两个链表合并为一个链表
- vc++6.0 MFC 分割窗体(Splitter Windows)
- 程序员之路——一个老程序员对刚上大学的学弟学妹的忠告
- vc模拟鼠标键盘操作实用类
- 猜猜我在想什么(以及动画xml的设置)
- 堆排序Java实现
- 我的第一个游戏FoodieThebug完成之后的心得体会--子龙山人
- 使用笔记本扩展并口+sjf2410烧写bootloader .
- 通过设置Bitmap旋转ImageView(动态旋转图片)
- 第一次移植uboot(1) .
- 古天乐养生经验——如何保持身体健康?
- Android-Lint:查错与代码优化利器
- 第一次移植uboot(2)(NAND中环境变量读写) .