九宫格牌翻转游戏demo
java关键代码: mText = (TextView) findViewById(R.id.textView1); mImageView01 = (ImageView) findViewById(R.id.m1); mButton = (Button) findViewById(R.id.button1); randon(); mImageView01.setOnClickListener(new View.OnClickListener() { @SuppressWarnings("deprecation") public void onClick(View v) { if(check1 == true && num > 0 && num1 == false) { num--; num1 = true; choose1 = true; if(turn1 == false) { turnAnim(mImageView01,s1[0]); if(s1[0] == R.drawable.b) { num = 0 ; friendState = true; } turn1 = true; } } }); mButton.setOnClickListener(new Button.OnClickListener() { @SuppressWarnings("deprecation") public void onClick(View v) { friendState = false; xianshi = 3; mText.setText("还剩"+xianshi+"次机会。"); num = 3; }); } /*往回洗牌的动画*/ public void backAnim(final ImageView a) { Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.back_scale); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { a.setImageDrawable(getResources().getDrawable( R.drawable.pbg)); // bool = true; //通过AnimationUtils得到动画配置文件(/res/anim/front_scale.xml),然后在把动画交给ImageView a.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.front)); } }); a.startAnimation(animation); } /*翻牌的动画*/ public void turnAnim(final ImageView a,final int b) { Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.back_scale); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { a.setImageDrawable(getResources().getDrawable(b)); // bool = true; //通过AnimationUtils得到动画配置文件(/res/anim/front_scale.xml),然后在把动画交给ImageView a.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.front)); } }); a.startAnimation(animation); if (b == R.drawable.b) { mText.setText("哇!你猜对了噢!!拍拍手!"); } else { if(xianshi >= 1) { mText.setText("还剩"+xianshi+"次机会。"); } else{ mText.setText("机会已用完!"); } } } private void randon() { // TODO Auto-generated method stub for (int i = 0; i < 9; i++) { int tmp = s1[i]; int s = (int) (Math.random() * 9); s1[i] = s1[s]; s1[s] = tmp; } } } res/layout/activity_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="#000000" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".EX04_06" > <LinearLayout android:id="@+id/LayoutButtons3" android:layout_marginTop="5dp" android:layout_width="230dp" android:layout_height="95dp" android:layout_centerHorizontal="true" android:layout_weight="1" android:orientation="horizontal" > <ImageView android:id="@+id/m1" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop"/> <ImageView android:id="@+id/m2" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop"/> <ImageView android:id="@+id/m3" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop" /> </LinearLayout> <LinearLayout android:id="@+id/LayoutButtons4" android:layout_below="@+id/LayoutButtons3" android:layout_width="230dp" android:layout_height="95dp" android:layout_centerHorizontal="true" android:layout_weight="1" android:orientation="horizontal" > <ImageView android:id="@+id/m4" android:layout_below="@+id/LayoutButtons3" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop" /> <ImageView android:id="@+id/m5" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop" /> <ImageView android:id="@+id/m6" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop" /> </LinearLayout> <LinearLayout android:id="@+id/LayoutButtons5" android:layout_below="@+id/LayoutButtons4" android:layout_width="230dp" android:layout_height="95dp" android:layout_centerHorizontal="true" android:layout_weight="1" android:orientation="horizontal" > <ImageView android:id="@+id/m7" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop" /> <ImageView android:id="@+id/m8" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop" /> <ImageView android:id="@+id/m9" android:layout_margin= "2dp" android:layout_width="60dp" android:layout_height="90dp" android:layout_weight="1" android:src="@drawable/pbg" android:scaleType="centerCrop" /> </LinearLayout> <TextView android:id="@+id/textView1" android:layout_below="@+id/LayoutButtons5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="2dp" android:text="猜猜是哪张" android:textSize="20sp" /> <Button android:id="@+id/button1" android:layout_width="120dp" android:layout_height="60dp" android:layout_alignTop="@+id/textView1" android:layout_centerHorizontal="true" android:text="再玩一次!" /> </RelativeLayout> res/anim/back_ainm.xml: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <scale android:fromXScale="1.0" android:toXScale="0.0" android:fromYScale="1.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="150"/> </set> res/anim/front.xml: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator"> <scale android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="1.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="150"/> </set>
- 1
- lijiao20442016-06-27资源 不错,先学习了
- 粉丝: 4
- 资源: 14
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助