知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X(jué)表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷(xiāo)的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷(xiāo)工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
硬幣反轉(zhuǎn)效果
發(fā)表時(shí)間:2020-10-19
發(fā)布人:葵宇科技
瀏覽次數(shù):57
反轉(zhuǎn)效不雅是很常見(jiàn)的,以前應(yīng)用的時(shí)刻,每次都要從新寫(xiě),如今寫(xiě)了一個(gè)對(duì)象類(lèi),便利應(yīng)用。
這里主如果感化于兩個(gè)View之間的反轉(zhuǎn),類(lèi)似于硬幣的反轉(zhuǎn)。
1.應(yīng)用扭遷移轉(zhuǎn)變畫(huà)RotateAnimation,然則要應(yīng)用帶有深度的RotateAnimation動(dòng)畫(huà)
下載地址:http://download.csdn.net/detail/forwardyzk/8328895
2.如不雅是點(diǎn)擊的┞俘面View,順時(shí)針扭轉(zhuǎn),那么就先把父窗體(包含正面View和后頭View)扭轉(zhuǎn)大年夜0~90,動(dòng)畫(huà)停止后,正面View隱蔽,后頭view顯示出來(lái)。
如不雅點(diǎn)擊的是后頭View,逆時(shí)針扭轉(zhuǎn),那么就把父窗體大年夜扭轉(zhuǎn)180~90,動(dòng)畫(huà)停止后,正面View顯示出來(lái),后頭View隱蔽。
3.為第一個(gè)動(dòng)畫(huà)添加動(dòng)畫(huà)監(jiān)聽(tīng),在動(dòng)畫(huà)停止后,履行另一半的動(dòng)畫(huà)。
設(shè)置點(diǎn)擊View的第一個(gè)動(dòng)畫(huà)
/** * @param position * 0表示的是順時(shí)針 1表示的是逆時(shí)針 * @param start * 開(kāi)端扭轉(zhuǎn)的角度 * @param end * 停止的角度 */ private void applyRotation(int position, float start, float end) { // 獲取View的中間腸位 final float centerX = mContainer.getWidth() / 2.0f; final float centerY = mContainer.getHeight() / 2.0f; // 創(chuàng)建一個(gè)帶有深度3D扭遷移轉(zhuǎn)變畫(huà) final RotateAnimation rotation = new RotateAnimation(start, end, centerX, centerY, 310.0f, true); rotation.setDuration(500); rotation.setFillAfter(true); // 加快效不雅 rotation.setInterpolator(new AccelerateInterpolator()); rotation.setAnimationListener(new DisplayNextView(position));// 當(dāng)前動(dòng)畫(huà)的監(jiān)聽(tīng)器,當(dāng)前動(dòng)畫(huà)停止時(shí),可以進(jìn)行開(kāi)啟下一動(dòng)畫(huà) mContainer.startAnimation(rotation); }
個(gè)中RotateAnimation rotation = new RotateAnimation(start, end,centerX, centerY, 310.0f, true);
310.0表示扭轉(zhuǎn)的深度,就是在Z軸偏向的深度。
給這個(gè)動(dòng)畫(huà)添加了監(jiān)聽(tīng)DisplayNextView,表示動(dòng)畫(huà)的監(jiān)聽(tīng)器
private final class DisplayNextView implements Animation.AnimationListener { private final int mPosition; private DisplayNextView(int position) { mPosition = position; } public void onAnimationStart(Animation animation) { } public void onAnimationEnd(Animation animation) { mContainer.post(new SwapViews(mPosition)); } public void onAnimationRepeat(Animation animation) { } }
個(gè)中position表示的是,在第一次的動(dòng)畫(huà)的時(shí)刻,是順時(shí)針照樣逆時(shí)針。
在onAnimationEnd中發(fā)送了一個(gè)通知,開(kāi)啟了一個(gè)線程,履行另一半動(dòng)畫(huà)。
/** * 交換正不和的另一半的動(dòng)畫(huà)效不雅 * */ private final class SwapViews implements Runnable { private final int mPosition; public SwapViews(int position) { mPosition = position; } public void run() { final float centerX = mContainer.getWidth() / 2.0f; final float centerY = mContainer.getHeight() / 2.0f; RotateAnimation rotation; if (mPosition == 0) { // 點(diǎn)擊的┞俘面 mFrontView.setVisibility(View.GONE); mBackView.setVisibility(View.VISIBLE); rotation = new RotateAnimation(90, 180, centerX, centerY, 310.0f, false); } else { // 點(diǎn)擊的后頭 mBackView.setVisibility(View.GONE); mFrontView.setVisibility(View.VISIBLE); rotation = new RotateAnimation(90, 0, centerX, centerY, 310.0f, false); } rotation.setDuration(500); rotation.setFillAfter(true); // 減速效不雅 rotation.setInterpolator(new DecelerateInterpolator()); mContainer.startAnimation(rotation); } }
會(huì)根據(jù)第一次的的position,
如不雅是表示的是順時(shí)針,那么后面一半的動(dòng)畫(huà)也應(yīng)當(dāng)是順時(shí)針。扭轉(zhuǎn)角度連起來(lái)就是0~90,90~180。
如不雅是表示的是逆時(shí)針,那么后面一半的動(dòng)畫(huà)也應(yīng)當(dāng)是逆時(shí)針。扭轉(zhuǎn)角度連起來(lái)就是180~90,90~0。
下面把順時(shí)針扭轉(zhuǎn)和逆時(shí)針扭轉(zhuǎn)封裝各自的辦法
/** * 點(diǎn)擊默認(rèn)正面View的動(dòng)畫(huà)效不雅 * * @param container * 最外部的View,frontView和backView的父窗體 * @param frontView * 默認(rèn)的┞俘面展示的View * @param backView * 默認(rèn)后頭展示的View */ public void clickFrontViewAnimation(View container, View frontView, View backView) { if (container == null || frontView == null || backView == null) { return; } this.mContainer = container; this.mFrontView = frontView; this.mBackView = backView; applyRotation(0, 0, 90); }
點(diǎn)擊默認(rèn)后頭的辦法
/** * 點(diǎn)擊默認(rèn)后頭View的動(dòng)畫(huà)效不雅 * * @param container * 最外部的View,frontView和backView的父窗體 * @param frontView * 默認(rèn)的┞俘面展示的View * @param backView * 默認(rèn)后頭展示的View */ public void clickBackViewAnimation(View container, View frontView, View backView) { if (container == null || frontView == null || backView == null) { return; } this.mContainer = container; this.mFrontView = frontView; this.mBackView = backView; applyRotation(1, 180, 90); }
下面介紹應(yīng)用步調(diào):
在activity_main.xml的構(gòu)造
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.yzk.rotatetow.MainActivity" > <ImageView android:id="@+id/front" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/front" android:visibility="visible" /> <ImageView android:id="@+id/back" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/back" android:visibility="gone" /> </RelativeLayout>
在MainActivity中寫(xiě)入代碼
[img]http://img.blog.csdn.net/20150105165621062?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9yd2FyZHl6aw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center [img]http://img.blog.csdn.net/20150105165742886?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9yd2FyZHl6aw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center [img]http://img.blog.csdn.net/20150105165810576?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9yd2FyZHl6aw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
思路:
public class MainActivity extends Activity implements OnClickListener { private RelativeLayout container; private ImageView front; private ImageView back; private TowRotateAnimation animaton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); initData(); } private void initView() { container = (RelativeLayout) findViewById(R.id.container); front = (ImageView) findViewById(R.id.front); back = (ImageView) findViewById(R.id.back); front.setOnClickListener(this); back.setOnClickListener(this); } private void initData() { animaton = new TowRotateAnimation(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.front: animaton.clickFrontViewAnimation(container, front, back); break; case R.id.back: animaton.clickBackViewAnimation(container, front, back); break; default: break; } } }
直接在View的點(diǎn)擊事宜中應(yīng)用TowRotateAnimation對(duì)象的辦法。
效不雅圖:
源碼下載:http://download.csdn.net/detail/forwardyzk/8329211
相關(guān)案例查看更多
相關(guān)閱讀
- 云南建站公司
- 云南網(wǎng)站建設(shè)公司地址
- 搜索引擎排名
- 英文網(wǎng)站建設(shè)公司
- 百度自然排名
- uniapp開(kāi)發(fā)小程序
- 開(kāi)通微信小程序被騙
- 云南軟件定制
- 網(wǎng)站維護(hù)
- 昆明小程序定制開(kāi)發(fā)
- 小程序定制開(kāi)發(fā)
- 云南網(wǎng)站建設(shè)靠譜公司
- 百度小程序
- 百度快速排名
- 云南網(wǎng)站建設(shè)首選
- 汽車(chē)報(bào)廢回收
- web前端
- 云南省建設(shè)廳網(wǎng)站
- 霸屏推廣
- 云南網(wǎng)站建設(shè)外包
- 云南小程序制作
- 云南小程序開(kāi)發(fā)課程
- 云南小程序公司
- 昆明小程序開(kāi)發(fā)
- 前端
- 網(wǎng)絡(luò)公司聯(lián)系方式
- 昆明軟件公司
- 小程序生成海報(bào)
- 云南百度小程序
- 河南小程序制作