Android slide-in slide-out for activity

送分小仙女□ 提交于 2019-11-30 14:29:37

问题


I have an Android app in which nine of the activities do not load a layout file. Their views are private classes which extend the View class. The activity construct view objects at runtime and uses these objects instead of layout files. The problem that I have is that the views created these activities should slide in and slide out both left and right when switching to other views. I have used a ViewFlipper before but I am unable to one with my need here since view flippers take layout files rather than activities. Is there any chance my problem can be solved without resolving to switching to layout files?


回答1:


Try thoses

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXDelta="-100%"
        android:toYDelta="0" />
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromXDelta="100%"
        android:fromYDelta="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXDelta="0"
        android:toYDelta="0" />
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromXDelta="-100%"
        android:fromYDelta="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXDelta="0"
        android:toYDelta="0" />
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="@android:integer/config_longAnimTime"
        android:fromXDelta="0"
        android:fromYDelta="0"
        android:interpolator="@android:anim/linear_interpolator"
        android:toXDelta="100%"
        android:toYDelta="0" />
</set>

And in the code when doing StartActivity()

overridePendingTransition(R.animator.anim_left, R.animator.anim_right);

and then when doing finish()

overridePendingTransition(R.animator.anim_left, R.animator.anim_right);



回答2:


this.overridePendingTransition(android.R.anim.slide_in_left,
                android.R.anim.slide_out_right);

write it just below of your Intent.



来源:https://stackoverflow.com/questions/17852481/android-slide-in-slide-out-for-activity

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