首页

android 转盘(简洁,效果也不错)

java

2020-7-29

package com.hck.youxi;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class MainActivity extends Activity {
	private GridView gridView;
	private int[] views1 = { R.drawable.study0_game01_0,
			R.drawable.study0_game02_0, R.drawable.study0_game03_0,
			R.drawable.study0_game04_0, R.drawable.study0_game_btn0,
			R.drawable.study0_game06_0, R.drawable.study0_game07_0,
			R.drawable.study0_game08_0, R.drawable.study0_game09_0 };

	private int[] views2 = { R.drawable.study0_game01_1,
			R.drawable.study0_game02_1, R.drawable.study0_game03_1,
			R.drawable.study0_game04_1, R.drawable.study0_game05_1,
			R.drawable.study0_game06_1, R.drawable.study0_game07_1,
			R.drawable.study0_game08_1, R.drawable.study0_game09_1 };
	private int[] ids = { 0, 1, 2, 5, 8, 7, 6, 3 };
	ChangeView changeView;
	private int id;
	private boolean isStart;
	private int startTime;
	private int stopTime;
	private Adpter adpter;
	private ImageView imageView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		imageView = (ImageView) findViewById(R.id.img);
		changeView = new ChangeView();
		gridView = (GridView) findViewById(R.id.gv);
		adpter = new Adpter();
		gridView.setAdapter(adpter);
		gridView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (isStart) {
					return;
				}
				if (arg2 == 4) {
					stopTime = new Random().nextInt(1600 * 5)   1600;
					new Thread(changeView).start();
					isStart = true;
				}
			}

		});
	}
	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			ChangeBG(ids[id]);
			id  ;
			if (id >= 8) {
				id = 0;
			}
		};
	};
	class ChangeView implements Runnable {
		@Override
		public void run() {
			Log.i("hck", "runrun");
			handler.sendEmptyMessage(0);
			if (startTime >= stopTime) {
				handler.removeCallbacks(changeView);
				isStart = false;
				startTime = 0;
				stopTime = 0;
				startAnim();
				return;
			}
			handler.postDelayed(changeView, 100);
			startTime  = 200;
		}
	}

	private void startAnim() {
		int[] oldP = new int[2];
		int[] newP = new int[2];
		gridView.getChildAt(4).getLocationOnScreen(newP);
		gridView.getChildAt(ids[id]).getLocationOnScreen(oldP);
		TranslateAnimation am = new TranslateAnimation(10, newP[0] - oldP[0],
				40, newP[1] - oldP[1]);
		// 动画开始到结束的执行时间(1000 = 1 秒)
		am.setDuration(3000);
		gridView.getChildAt(ids[id]).startAnimation(am);
		final Animation fadeIn = AnimationUtils.loadAnimation(this,
				R.anim.circle);
		imageView.setVisibility(View.VISIBLE);
		imageView.startAnimation(fadeIn);
		for (int i = 0; i < gridView.getChildCount(); i  ) {
			if (i == ids[id]) {
				continue;
			} else {
				gridView.getChildAt(i).setVisibility(View.GONE);
			}
		}
	}

	private void ChangeBG(int id) {
		for (int i = 0; i < gridView.getChildCount(); i  ) {
			if (i == id) {
				((ImageView) gridView.getChildAt(id))
						.setBackgroundResource(views2[id]);
			} else if (i == 4) {
				continue;
			} else {
				((ImageView) gridView.getChildAt(i))
						.setBackgroundResource(views1[i]);
			}
		}
	}

	class Adpter extends BaseAdapter {

		@Override
		public int getCount() {
			return views1.length;
		}

		@Override
		public Object getItem(int position) {
			return views1[position];
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			convertView = getLayoutInflater().inflate(R.layout.view_item, null);
			ImageView imageView = (ImageView) convertView
					.findViewById(R.id.image);
			imageView.setBackgroundResource(views1[position]);
			return convertView;
		}

	}
}
资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
android╫¬┼╠/Youxi/.classpath , 450
android╫¬┼╠/Youxi/.project , 808
android╫¬┼╠/Youxi/AndroidManifest.xml , 842
android╫¬┼╠/Youxi/bin/AndroidManifest.xml , 842
android╫¬┼╠/Youxi/bin/classes.dex , 561684
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/BuildConfig.class , 335
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/MainActivity$1.class , 909
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/MainActivity$2.class , 1607
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/MainActivity$Adpter.class , 1573
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/MainActivity$ChangeView.class , 1335
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/MainActivity.class , 4340
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$anim.class , 375
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$attr.class , 325
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$dimen.class , 446
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$drawable.class , 1198
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$id.class , 460
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$layout.class , 412
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$menu.class , 373
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$string.class , 457
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R$style.class , 416
android╫¬┼╠/Youxi/bin/classes/com/hck/youxi/R.class , 664
android╫¬┼╠/Youxi/bin/dexedLibs/android-support-v4-ec83073d0192ae07c440717bb25fde13.jar , 189231
android╫¬┼╠/Youxi/bin/jarlist.cache , 120
android╫¬┼╠/Youxi/bin/resources.ap_ , 1059276
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/home_bk.png , 517175
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/ic_launcher.png , 5964
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_bk.png , 62766
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game01_0.png , 18109
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game01_1.png , 18675
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game02_0.png , 19679
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game02_1.png , 22260
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game03_0.png , 16617
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game03_1.png , 16813
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game04_0.png , 24932
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game04_1.png , 32042
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game05_0.png , 15882
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game05_1.png , 15778
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game06_0.png , 17920
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game06_1.png , 18515
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game07_0.png , 32048
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game07_1.png , 33762
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game08_0.png , 21367
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game08_1.png , 23858
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game09_0.png , 20621
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game09_1.png , 22870
android╫¬┼╠/Youxi/bin/res/drawable-hdpi/study0_game_btn0.png , 40416
android╫¬┼╠/Youxi/bin/res/drawable-mdpi/ic_launcher.png , 3112
android╫¬┼╠/Youxi/bin/res/drawable-xhdpi/ic_launcher.png , 9355
android╫¬┼╠/Youxi/bin/res/drawable-xxhdpi/ic_launcher.png , 17889
android╫¬┼╠/Youxi/bin/Youxi.apk , 1255599
android╫¬┼╠/Youxi/gen/com/hck/youxi/BuildConfig.java , 155
android╫¬┼╠/Youxi/gen/com/hck/youxi/R.java , 3951
android╫¬┼╠/Youxi/ic_launcher-web.png , 51394
android╫¬┼╠/Youxi/libs/android-support-v4.jar , 484258
android╫¬┼╠/Youxi/proguard-project.txt , 781
android╫¬┼╠/Youxi/project.properties , 563
android╫¬┼╠/Youxi/res/anim/circle.xml , 462
android╫¬┼╠/Youxi/res/drawable-hdpi/home_bk.png , 517443
android╫¬┼╠/Youxi/res/drawable-hdpi/ic_launcher.png , 7658
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_bk.png , 99930
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game01_0.png , 17272
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game01_1.png , 19016
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game02_0.png , 19525
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game02_1.png , 22672
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game03_0.png , 16170
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game03_1.png , 17340
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game04_0.png , 24323
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game04_1.png , 33041
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game05_0.png , 15480
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game05_1.png , 15880
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game06_0.png , 17388
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game06_1.png , 18940
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game07_0.png , 31422
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game07_1.png , 30040
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game08_0.png , 20773
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game08_1.png , 24145
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game09_0.png , 19306
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game09_1.png , 22465
android╫¬┼╠/Youxi/res/drawable-hdpi/study0_game_btn0.png , 42356
android╫¬┼╠/Youxi/res/drawable-mdpi/ic_launcher.png , 3777
android╫¬┼╠/Youxi/res/drawable-xhdpi/ic_launcher.png , 12516
android╫¬┼╠/Youxi/res/drawable-xxhdpi/ic_launcher.png , 24777
android╫¬┼╠/Youxi/res/layout/main.xml , 715
android╫¬┼╠/Youxi/res/layout/view_item.xml , 481
android╫¬┼╠/Youxi/res/menu/main.xml , 254
android╫¬┼╠/Youxi/res/values-sw600dp/dimens.xml , 196
android╫¬┼╠/Youxi/res/values-sw720dp-land/dimens.xml , 269
android╫¬┼╠/Youxi/res/values-v11/styles.xml , 324
android╫¬┼╠/Youxi/res/values-v14/styles.xml , 381
android╫¬┼╠/Youxi/res/values/dimens.xml , 213
android╫¬┼╠/Youxi/res/values/strings.xml , 215
android╫¬┼╠/Youxi/res/values/styles.xml , 680
android╫¬┼╠/Youxi/src/com/hck/youxi/MainActivity.java , 4353
android╫¬┼╠/╦╡├≈.txt , 80
没有账号? 忘记密码?

社交账号快速登录