简体   繁体   English

用于活动的Android幻灯片滑出

[英]Android slide-in slide-out for activity

I have an Android app in which nine of the activities do not load a layout file. 我有一个Android应用程序,其中九个活动不加载布局文件。 Their views are private classes which extend the View class. 他们的观点是扩展View类的私有类。 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. 我以前使用过ViewFlipper,但由于浏览器脚本需要布局文件而不是活动,因此我无法满足我的需求。 Is there any chance my problem can be solved without resolving to switching to layout files? 如果不解决切换到布局文件,我的问题是否有可能得到解决?

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() 在执行StartActivity()时的代码中

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

and then when doing finish() 然后在做完()

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

write it just below of your Intent. 在你的意图下面写下它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM