android實(shí)現(xiàn)簡(jiǎn)單的活動(dòng)轉(zhuǎn)盤
本文實(shí)例為大家分享了android實(shí)現(xiàn)簡(jiǎn)單活動(dòng)轉(zhuǎn)盤的具體代碼,供大家參考,具體內(nèi)容如下
頁面
public class CircleTurntableActivity extends AppCompatActivity { private Animation mStartAnimation; private ImageView mLuckyTurntable; private boolean isRunning; private boolean mIsLucky = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_circle_turntable); mLuckyTurntable = (ImageView) findViewById(R.id.id_lucky_turntable); ImageView mStartBtn = (ImageView) findViewById(R.id.id_start_btn); mStartBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isRunning) { isRunning = true; mIsLucky = !mIsLucky; startAnimation(); } } }); } /** * 開啟動(dòng)畫 * 5秒旋轉(zhuǎn)5圈+中獎(jiǎng)所在位置角度 */ private void startAnimation() { float toDegree;//結(jié)束角度(以實(shí)際轉(zhuǎn)盤圖為準(zhǔn)計(jì)算角度) if (mIsLucky) { toDegree = 360 * 5 + 30f; } else { toDegree = 360 * 5 + 90f; } if (mStartAnimation != null) { mStartAnimation.reset(); } // 按中心點(diǎn)旋轉(zhuǎn) toDegree度 // 參數(shù):旋轉(zhuǎn)的開始角度、旋轉(zhuǎn)的結(jié)束角度、X軸的伸縮模式、X坐標(biāo)的伸縮值、Y軸的伸縮模式、Y坐標(biāo)的伸縮值 mStartAnimation = new RotateAnimation(0, toDegree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mStartAnimation.setDuration(5000); // 設(shè)置旋轉(zhuǎn)時(shí)間 mStartAnimation.setRepeatCount(0); // 設(shè)置重復(fù)次數(shù) mStartAnimation.setFillAfter(true);// 動(dòng)畫執(zhí)行完后是否停留在執(zhí)行完的狀態(tài) mStartAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); // 動(dòng)畫播放的速度 mStartAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { isRunning = false; Toast.makeText(CircleTurntableActivity.this, mIsLucky ? "精美禮品" : "謝謝參與", Toast.LENGTH_SHORT).show(); } @Override public void onAnimationRepeat(Animation animation) { } }); mLuckyTurntable.startAnimation(mStartAnimation); } }
頁面布局
<?xml version="1.0" encoding="utf-8"?> <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"> <!--轉(zhuǎn)盤--> <ImageView android:id="@+id/id_lucky_turntable" android:layout_width="613.33px" android:layout_height="613.33px" android:layout_centerInParent="true" android:src="@mipmap/lucky_turntable_bg" /> <!--指針--> <ImageView android:paddingBottom="40px" android:id="@+id/id_start_btn" android:layout_width="266.66px" android:layout_height="266.66px" android:layout_centerInParent="true" android:src="@mipmap/lucky_start_icon" /> </RelativeLayout>
效果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 實(shí)現(xiàn)錨點(diǎn)定位思路詳解
本篇文章就使用tablayout、scrollview來實(shí)現(xiàn)android錨點(diǎn)定位的功能。通過<a href="#head" rel="external nofollow" > 去設(shè)置頁面內(nèi)錨點(diǎn)定位跳轉(zhuǎn)。具體實(shí)現(xiàn)思路大家跟隨腳本之家小編一起通過本文看下吧2018-07-07android?studio后臺(tái)服務(wù)使用詳解
這篇文章主要為大家詳細(xì)介紹了android?studio后臺(tái)服務(wù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08Android中庫(kù)項(xiàng)目的使用方法圖文介紹
類似開發(fā)其他Java應(yīng)用一樣,我們可以將可復(fù)用的代碼,打成一個(gè)jar包,供所有需要的項(xiàng)目使用。這樣,可以解決很大一部分代碼復(fù)用的問題,本文將詳細(xì)介紹,需要了解的朋友可以參考下2012-12-12Android應(yīng)用開發(fā)中自定義ViewGroup的究極攻略
這里我們要演示的自定義ViewGroup中將實(shí)現(xiàn)多種方式排列和滑動(dòng)等效果,并且涵蓋子View之間Touch Event的攔截與處理等問題,完全干貨,下面就為大家送上Android應(yīng)用開發(fā)中自定義ViewGroup的究極實(shí)例攻略2016-05-05Flutter?Ping檢查服務(wù)器通訊信號(hào)強(qiáng)度實(shí)現(xiàn)步驟
這篇文章主要為大家介紹了Flutter?Ping檢查服務(wù)器通訊信號(hào)強(qiáng)度實(shí)現(xiàn)步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06Android 獲取內(nèi)外SD卡路徑幾種方法總結(jié)
這篇文章主要介紹了Android 獲得內(nèi)外SD卡路徑幾種方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2016-12-12Android實(shí)現(xiàn)邊錄邊播應(yīng)用
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)邊錄邊播應(yīng)用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11Android使用WebView實(shí)現(xiàn)文件下載功能
這篇文章主要為大家詳細(xì)介紹了Android使用WebView實(shí)現(xiàn)文件下載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05