付費(fèi)下載
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、簡(jiǎn)單實(shí)現(xiàn)Android圖片翻轉(zhuǎn)動(dòng)畫效果不說廢話,先看效果。這是原始圖片的樣子這是翻轉(zhuǎn)后的效果圖如果是你想要的效果,那么繼續(xù)往下看,如果不是,那可以跳過了。這是一個(gè)動(dòng)畫,而不是用matrix實(shí)現(xiàn)的直接翻轉(zhuǎn)圖片??赡芫W(wǎng)上有很多例子了,但我這是我自己實(shí)驗(yàn)過的,單純的翻轉(zhuǎn)一張圖片。我這個(gè)是根據(jù)APIDemo簡(jiǎn)單修改寫的需要一個(gè)Rotate3d 類,繼承Animationpublic class Rotate3d extends Animationprivate final float mFromDegrees; private final float mToDegrees; private final
2、 float mCenterX; private final float mCenterY; private final float mDepthZ; private final boolean mReverse; private Camera mCamera; public Rotate3d(float fromDegrees, float toDegrees, float centerX, float centerY, float depthZ, boolean reverse) mFromDegrees = fromDegrees; mToDegrees = toDegrees; mCe
3、nterX = centerX; mCenterY = centerY; mDepthZ = depthZ; mReverse = reverse; Override public void initialize(int width, int height, int parentWidth, int parentHeight) super.initialize(width, height, parentWidth, parentHeight); mCamera = new Camera(); Override protected void applyTransformation(float i
4、nterpolatedTime, Transformation t) final float fromDegrees = mFromDegrees; float degrees = fromDegrees + (mToDegrees - fromDegrees) * interpolatedTime); final float centerX = mCenterX; final float centerY = mCenterY; final Camera camera = mCamera; final Matrix matrix = t.getMatrix(); camera.save();
5、if (mReverse) camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime); else camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime); camera.rotateY(degrees); camera.getMatrix(matrix); camera.restore(); matrix.preTranslate(-centerX, -centerY); matrix.postTranslate(centerX, centerY); 這個(gè)類可以直接
6、拷過去,不用做任何的修改。其中的方法自己找相關(guān)資料研究。在main.xml里加個(gè)ImageView,如這個(gè)不需要解釋吧,都可以看懂的最后,還需要一個(gè)activity類如:public class TestRotate extends Activity implements OnClickListenerprivate mageView imageview;private ViewGroup mContainer;/* *這個(gè)變量設(shè)置的是圖片,如果是多張圖片,那么可以用數(shù)組,如 *private static final int IMAGE = new int *R.drawable.ro, *
7、R.drawable.icon *; *有多少圖片就放多少,我這里做的只是一張圖片的翻轉(zhuǎn) * */private static final int IMAGE = R.drawable.ro; /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); imageview = (ImageView) findVi
8、ewById(R.id.image); mContainer = (ViewGroup) findViewById(R.id.container); /* * 設(shè)置最新顯示的圖片 * 如果是數(shù)組,那么可以寫成IMAGEint * */ imageview.setImageResource(IMAGE); /* * * 設(shè)置ImageView的OnClickListener * */ imageview.setClickable(true); imageview.setFocusable(true); imageview.setOnClickListener(this); private voi
9、d applyRotation(int position, float start, float end) / Find the center of the container final float centerX = mContainer.getWidth() / 2.0f; final float centerY = mContainer.getHeight() / 2.0f; final Rotate3d rotation = new Rotate3d(start, end, centerX, centerY, 310.0f, true); rotation.setDuration(5
10、00); rotation.setFillAfter(true); rotation.setInterpolator(new AccelerateInterpolator(); rotation.setAnimationListener(new DisplayNextView(position); mContainer.startAnimation(rotation); Overridepublic void onClick(View v) / TODO Auto-generated method stub/* * * 調(diào)用這個(gè)方法,就是翻轉(zhuǎn)圖片 * 參數(shù)很簡(jiǎn)單,大家都應(yīng)該看得懂 * 簡(jiǎn)單說下
11、,第一個(gè)是位置,第二是開始的角度,第三個(gè)是結(jié)束的角度 * 這里需要說明的是,如果是要回到上一張 * 把第一個(gè)參數(shù)設(shè)置成-1就行了 * */applyRotation(0,0,90);private final class DisplayNextView implements Animation.AnimationListener private final int mPosition; private DisplayNextView(int position) mPosition = position; public void onAnimationStart(Animation animat
12、ion) public void onAnimationEnd(Animation animation) mContainer.post(new SwapViews(mPosition); public void onAnimationRepeat(Animation animation) /* * This class is responsible for swapping the views and start the second * half of the animation. */ private final class SwapViews implements Runnable p
13、rivate 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; Rotate3d rotation; if (mPosition -1) imageview.setVisibility(View.VISIBLE); imageview.requestFoc
14、us(); rotation = new Rotate3d(90, 180, centerX, centerY, 310.0f, false); else imageview.setVisibility(View.GONE); rotation = new Rotate3d(90, 0, centerX, centerY, 310.0f, false); rotation.setDuration(500); rotation.setFillAfter(true); rotation.setInterpolator(new DecelerateInterpolator(); mContainer.startA
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 市場(chǎng)集中度變遷分析-洞察與解讀
- 數(shù)據(jù)可視化評(píng)估體系-洞察與解讀
- 3D打印支架細(xì)胞粘附調(diào)控-洞察與解讀
- 異構(gòu)數(shù)據(jù)對(duì)齊技術(shù)-洞察與解讀
- 全球綠色能源治理體系-洞察與解讀
- 可持續(xù)材料的新興應(yīng)用-洞察與解讀
- 可降解包裝材料性能-洞察與解讀
- 低碳社區(qū)空間布局-洞察與解讀
- 在線課程質(zhì)量評(píng)估-第1篇-洞察與解讀
- 醫(yī)院信息管理系統(tǒng)應(yīng)用培訓(xùn)
- 新疆環(huán)保行業(yè)前景分析報(bào)告
- 2025~2026學(xué)年福建省泉州五中七年級(jí)上學(xué)期期中測(cè)試英語試卷
- 聯(lián)合辦公合同范本
- 2025年生物多樣性保護(hù)與生態(tài)修復(fù)項(xiàng)目可行性研究報(bào)告
- 2025年黑龍江省檢察院公益訴訟業(yè)務(wù)競(jìng)賽測(cè)試題及答案解析
- 一氧化碳中毒救治課件
- 廣東事業(yè)單位歷年考試真題及答案
- 《會(huì)計(jì)信息化工作規(guī)范》解讀(楊楊)
- 工程機(jī)械設(shè)備租賃服務(wù)方案投標(biāo)文件(技術(shù)方案)
- 高海拔地區(qū)GNSS大壩監(jiān)測(cè)技術(shù)研究
- 實(shí)施指南(2025)《DL-T 1630-2016氣體絕緣金屬封閉開關(guān)設(shè)備局部放電特高頻檢測(cè)技術(shù)規(guī)范》
評(píng)論
0/150
提交評(píng)論