亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android圖片翻轉(zhuǎn)動畫簡易實現(xiàn)代碼

 更新時間:2012年11月28日 11:25:06   作者:  
Android圖片翻轉(zhuǎn)動畫效果如何實現(xiàn),本文將給你一個驚喜,實現(xiàn)代碼已經(jīng)列出,需要的朋友可以參考下

下面給大家分享一個有趣的動畫:這里比較適合一張圖片的翻轉(zhuǎn),如果是多張圖片,可以參考APIDemo里的例子,就是加個ArrayAdapter,還是簡單的,也可以自己發(fā)揮修改,實現(xiàn)自己想要的。這里的代碼基本上可以直接運行項目了。
在main.xml里加個ImageView,如

復(fù)制代碼 代碼如下:

<?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>

這個不需要解釋吧,都可以看懂的
最后,還需要一個activity類
如:
復(fù)制代碼 代碼如下:

public class TestRotate extends Activity implements OnClickListener{
private mageView imageview;
private ViewGroup mContainer;
/**
*這個變量設(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)用這個方法,就是翻轉(zhuǎn)圖片
* 參數(shù)很簡單,大家都應(yīng)該看得懂
* 簡單說下,第一個是位置,第二是開始的角度,第三個是結(jié)束的角度
* 這里需要說明的是,如果是要回到上一張
* 把第一個參數(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);
}
}
}

相關(guān)文章

  • 仿餓了嗎點餐界面兩個ListView聯(lián)動效果

    仿餓了嗎點餐界面兩個ListView聯(lián)動效果

    這篇文章主要介紹了仿餓了點餐界面2個ListView聯(lián)動效果的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-09-09
  • android控制密碼顯示與隱藏的方法

    android控制密碼顯示與隱藏的方法

    這篇文章主要為大家詳細介紹了android控制密碼顯示與隱藏的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android Handler leak分析及解決辦法詳解

    Android Handler leak分析及解決辦法詳解

    這篇文章主要介紹了Android Handler leak分析及解決辦法詳解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • Android 實現(xiàn)圓角圖片的簡單實例

    Android 實現(xiàn)圓角圖片的簡單實例

    這篇文章主要介紹了Android 實現(xiàn)圓角圖片的簡單實例的相關(guān)資料,Android 圓角圖片的實現(xiàn)形式,包括用第三方、也有系統(tǒng),需要的朋友可以參考下
    2017-07-07
  • Android記事本項目開發(fā)

    Android記事本項目開發(fā)

    這篇文章主要為大家詳細介紹了Android記事本項目開發(fā)的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android登錄代碼MVP架構(gòu)詳解

    Android登錄代碼MVP架構(gòu)詳解

    這篇文章主要為大家詳細介紹了Android登錄代碼MVP架構(gòu)的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android中Permission權(quán)限機制的具體使用

    Android中Permission權(quán)限機制的具體使用

    這篇文章主要介紹了Android中Permission權(quán)限機制的具體使用,本文講解了權(quán)限級別 protection level、ICC(inter-component communication)權(quán)限保護等內(nèi)容,需要的朋友可以參考下
    2015-04-04
  • Android MarginDesign控件TabLayout導(dǎo)航欄使用詳解

    Android MarginDesign控件TabLayout導(dǎo)航欄使用詳解

    這篇文章主要為大家詳細介紹了Android MarginDesign控件TabLayout導(dǎo)航欄使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • ERROR/AndroidRuntime(17121)的問題解決

    ERROR/AndroidRuntime(17121)的問題解決

    ERROR/AndroidRuntime(17121)的問題解決,需要的朋友可以參考一下
    2013-05-05
  • Android Universal ImageLoader 緩存圖片

    Android Universal ImageLoader 緩存圖片

    Universal Image Loader for Android的目的是為了實現(xiàn)異步的網(wǎng)絡(luò)圖片加載、緩存及顯示,支持多線程異步加載,通過本文給大家介紹Android Universal ImageLoader緩存圖片相關(guān)資料,涉及到imageloader緩存圖片相關(guān)知識,對imageloader緩存圖片相關(guān)知識感興趣的朋友一起學(xué)習(xí)
    2016-01-01

最新評論