How can i make a dynamic flipping screen(like that of iPhone) in Android

喜你入骨 提交于 2019-11-29 20:31:38

You can add pages to a ViewFlipper dynamically using addView.

  flipper= (ViewFlipper) findViewById(R.id.flipper1);
  flipper.addView(myView,myViewIndex);

Where myView is the view you wish to add, and myViewIndex is the index in the viewflipper you want to add this new view.

You can then set the animations to preform on changing of views:

  flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in));
  flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out));

Then to flip to this page you can use:

  flipper.setDisplayedChild(myViewIndex);

Where left_in.xml is defined as

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
  android:interpolator="@android:anim/accelerate_interpolator">
    <translate
    android:interpolator="@android:anim/decelerate_interpolator"
    android:fromXDelta="100%p"
    android:toXDelta="0" 
    android:duration="300"
    />
</set>

and left_out.xml is:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/accelerate_interpolator"
    >
    <translate
    android:interpolator="@android:anim/decelerate_interpolator"
    android:fromXDelta="0" 
    android:toXDelta="-100%p" 
    android:duration="300"
    />
</set>

Just had a quick look for you because I was sure I've seen it around before, I found this on developer.android.com:

public void overridePendingTransition (int enterAnim, int exitAnim)

Since: API Level 5
Call immediately after one of the flavors of startActivity(Intent) or finish() to specify an explicit transition animation to perform next.
Parameters
enterAnim   A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitAnim    A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.

So you can add this extra parameter to your intent which will define how the activity you call will animate on entrance of new activity and exit of old activity.

If you want to navigate between two activities and not use a view flipper you can use normal intents. Wrote a tutorial so that you can animate your activity's in and out,

Enjoy:

http://blog.blundell-apps.com/animate-an-activity/

Do you just want the screen to rotate based off of the position it is being held in (as determined by the accelerometer sensors)?

If so just add

android:screenOrientation="sensor"

to the Activity node in your AndroidManifest.xml file

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