how to flip images like 3d animation in android?

天大地大妈咪最大 提交于 2019-12-08 04:05:22

问题


i have images in 3d for example 1-10 images

in which i have (1-5) images from front to back in 3d shape left ward and similarly front to back right ward (6-10)

if we look at them a complete 3d shape is formed i want to use them with left and right swipe/flipping so that complete 3d view of that image is displayed.

i have seen this example but its far away from my view flipper and swipe. http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html

any one guide me how to achieve this?

any help would be appreciated.


回答1:


You can add realistic 3D flip transition by building on Raghav Chopra's the 3D flip library https://code.google.com/p/android-3d-flip-view-transition.

With that, all you have to do is instead of calling flipper.showNext(); call AnimationFactory.flipTransition(flipper, FlipDirection.LEFT_RIGHT); and you are done. The 3D animation is pretty cool.

A lot of the other tutorials and sample codes (including the one you are using) don't produce believable 3D flips. A simple rotation on the y-axis isn't sufficient so take a look the above linke (or this video http://youtu.be/52mXHqX9f3Y).

If you want to have it automatically transition, simply add a Handler like:

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

The above will keep flipping through the images, indefinitely (cycling back to the first image at the end). To stop the auto transition, you add a boolean flag that you check before starting the flip, or save the Runnable you are using and call handler.removeCallbacks(runnable).




回答2:


xml for the flipping

<?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();
}
});
}
}

this is a manual flipping

The result is a trivial activity: click the button, and the next TextView in sequence is displayed, wrapping around to the first after viewing the last



来源:https://stackoverflow.com/questions/8340396/how-to-flip-images-like-3d-animation-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!