簡體   English   中英

如何在Android中翻轉3d動畫之類的圖像?

[英]how to flip images like 3d animation in android?

我有3d圖像,例如1-10圖像

其中我有(1-5)圖像從前到后的3d形狀左病房和類似的前后到右病房(6-10)

如果我們看着它們形成了完整的3d形狀,我想通過左右滑動/翻轉來使用它們,以便顯示該圖像的完整3d視圖。

我已經看到了這個示例,但是它離我的視野鰭狀肢和滑動區域很遠。 http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

任何人都指導我如何實現這一目標?

任何幫助,將不勝感激。

您可以通過在Raghav Chopra的3D翻轉庫https://code.google.com/p/android-3d-flip-view-transition上構建來添加逼真的3D翻轉過渡。

有了這個,你所要做的就是不要調用flipper.showNext(); 調用AnimationFactory.flipTransition(flipper, FlipDirection.LEFT_RIGHT); 你完成了 3D動畫非常酷。

許多其他教程和示例代碼(包括您正在使用的代碼)不會產生可信的3D翻轉。 在y軸上的簡單旋轉是不夠的,所以看看上面的linke(或這個視頻http://youtu.be/52mXHqX9f3Y )。

如果您想讓它自動轉換,只需添加一個Handler如:

Handler handler = new Handler();
...
handler.postDelayed(new Runnable() {
    AnimationFactory.flipTransition(flipper, FlipDirection.LEFT_RIGHT);
}, 500);

以上內容將無限期地翻轉圖像(最后循環回到第一張圖像)。 要停止自動轉換,請添加在開始翻轉之前檢查的布爾標志,或者保存您正在使用的Runnable並調用handler.removeCallbacks(runnable)

xml用於翻轉

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/flip_me"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flip Me!"
/>
<ViewFlipper android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#FF00FF00"
android:text="This is the first panel"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#FFFF0000"
android:text="This is the second panel"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#FFFFFF00"
android:text="This is the third panel"
/>
</ViewFlipper>
</LinearLayout>

java Filee

public class FlipperDemo extends Activity {
ViewFlipper flipper;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
flipper=(ViewFlipper)findViewById(R.id.details);
Button btn=(Button)findViewById(R.id.flip_me);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
flipper.showNext();
}
});
}
}

這是手動翻轉

結果是一個微不足道的活動:單擊按鈕,然后依次顯示下一個TextView,在查看最后一個之后,環繞到第一個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM