Android圖片翻轉(zhuǎn)動(dòng)畫簡易實(shí)現(xiàn)代碼
下面給大家分享一個(gè)有趣的動(dòng)畫:這里比較適合一張圖片的翻轉(zhuǎn),如果是多張圖片,可以參考APIDemo里的例子,就是加個(gè)ArrayAdapter,還是簡單的,也可以自己發(fā)揮修改,實(shí)現(xiàn)自己想要的。這里的代碼基本上可以直接運(yùn)行項(xiàng)目了。
在main.xml里加個(gè)ImageView,如
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate"
android:textSize="50px"
android:layout_x="150px"
android:layout_y="30px"
android:src="@drawable/ro">
></ImageView>
</FrameLayout>
這個(gè)不需要解釋吧,都可以看懂的
最后,還需要一個(gè)activity類
如:
public class TestRotate extends Activity implements OnClickListener{
private mageView imageview;
private ViewGroup mContainer;
/**
*這個(gè)變量設(shè)置的是圖片,如果是多張圖片,那么可以用數(shù)組,如
*private static final int IMAGE = new int[]{
* R.drawable.ro,
* 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) findViewById(R.id.image);
mContainer = (ViewGroup) findViewById(R.id.container);
/**
* 設(shè)置最新顯示的圖片
* 如果是數(shù)組,那么可以寫成IMAGE[int]
*
*/
imageview.setImageResource(IMAGE);
/**
*
* 設(shè)置ImageView的OnClickListener
*
*/
imageview.setClickable(true);
imageview.setFocusable(true);
imageview.setOnClickListener(this);
}
private void 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(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(new DisplayNextView(position));
mContainer.startAnimation(rotation);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
/**
*
* 調(diào)用這個(gè)方法,就是翻轉(zhuǎn)圖片
* 參數(shù)很簡單,大家都應(yīng)該看得懂
* 簡單說下,第一個(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 animation) {
}
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 {
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;
Rotate3d rotation;
if (mPosition > -1) {
imageview.setVisibility(View.VISIBLE);
imageview.requestFocus();
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.startAnimation(rotation);
}
}
}
- Android仿京東頂部搜索框滑動(dòng)伸縮動(dòng)畫效果
- Android實(shí)現(xiàn)頁面滑動(dòng)切換動(dòng)畫
- Android實(shí)現(xiàn)手勢(shì)滑動(dòng)和簡單動(dòng)畫效果
- Android程序開發(fā)之使用Design包實(shí)現(xiàn)QQ動(dòng)畫側(cè)滑效果和滑動(dòng)菜單導(dǎo)航
- Android編程實(shí)現(xiàn)ViewPager多頁面滑動(dòng)切換及動(dòng)畫效果的方法
- Android Tween動(dòng)畫之RotateAnimation實(shí)現(xiàn)圖片不停旋轉(zhuǎn)效果實(shí)例介紹
- android實(shí)現(xiàn)圖片閃爍動(dòng)畫效果的兩種實(shí)現(xiàn)方式(實(shí)用性高)
- Android Glide圖片加載(加載監(jiān)聽、加載動(dòng)畫)
- Android實(shí)現(xiàn)圖片點(diǎn)擊預(yù)覽效果(zoom動(dòng)畫)
- Android實(shí)現(xiàn)ViewFlipper圖片動(dòng)畫滑動(dòng)
相關(guān)文章
仿餓了嗎點(diǎn)餐界面兩個(gè)ListView聯(lián)動(dòng)效果
這篇文章主要介紹了仿餓了點(diǎn)餐界面2個(gè)ListView聯(lián)動(dòng)效果的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09Android 實(shí)現(xiàn)圓角圖片的簡單實(shí)例
這篇文章主要介紹了Android 實(shí)現(xiàn)圓角圖片的簡單實(shí)例的相關(guān)資料,Android 圓角圖片的實(shí)現(xiàn)形式,包括用第三方、也有系統(tǒng),需要的朋友可以參考下2017-07-07Android中Permission權(quán)限機(jī)制的具體使用
這篇文章主要介紹了Android中Permission權(quán)限機(jī)制的具體使用,本文講解了權(quán)限級(jí)別 protection level、ICC(inter-component communication)權(quán)限保護(hù)等內(nèi)容,需要的朋友可以參考下2015-04-04Android MarginDesign控件TabLayout導(dǎo)航欄使用詳解
這篇文章主要為大家詳細(xì)介紹了Android MarginDesign控件TabLayout導(dǎo)航欄使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01ERROR/AndroidRuntime(17121)的問題解決
ERROR/AndroidRuntime(17121)的問題解決,需要的朋友可以參考一下2013-05-05Android Universal ImageLoader 緩存圖片
Universal Image Loader for Android的目的是為了實(shí)現(xiàn)異步的網(wǎng)絡(luò)圖片加載、緩存及顯示,支持多線程異步加載,通過本文給大家介紹Android Universal ImageLoader緩存圖片相關(guān)資料,涉及到imageloader緩存圖片相關(guān)知識(shí),對(duì)imageloader緩存圖片相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)2016-01-01