在滑到另一个XML布局按钮被点击时 [英] Slide in another XML layout when button is clicked

查看:140
本文介绍了在滑到另一个XML布局按钮被点击时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的main.xml 布局文件和我的Java code,我做从布局,并希望以显示为result.xml 布局文件。我知道我可以使用动画文件夹来保存动画slidei n中的结果布局如下所示:

I have a main.xml layout file and in my Java code, I am doing some calculation taken from the main layout and wanting to display in result.xml layout file. I know I can use the anim folder to hold the animation to slidei n the result layout like the following:

左至右依次为:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate android:fromXDelta="-100%" android:toXDelta="0%"
             android:fromYDelta="0%" android:toYDelta="0%"
             android:duration="700"/>
</set>

从右至左:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate
     android:fromXDelta="0%" android:toXDelta="100%"
     android:fromYDelta="0%" android:toYDelta="0%"
     android:duration="700" />
</set>

我不知道如何执行上述被点击了布局文件中的按钮,所以当,在结果布局文件从右侧滑入英寸而且,如果我想回去的布局我可以preSS一个按钮(结果添加布局)向右滑动布局文件

I was wondering how to implement the above so when the button is clicked on the main layout file, the result layout file slides in from the right. And also if I wanted to go back to the main layout I can press a button (added on result layout) to slide right the main layout file

推荐答案

您也可以使用此功能:<一href=\"http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition%28int,%20int%29\"相对=nofollow> overridePendingTransition 它可以定义为即将到来的活动的动画和动画等为活动而退出。

You can also use this function : overridePendingTransition which can define an animation for the upcoming activity and an other animation for the activity which exit.

使用像这样,在你的第二个活动:

Use it like this, in your second Activity :

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(android.R.anim.slide_out_right, 0);
    setContentView(R.layout.myLayout);

第一个参数是为动画输入,而0是没有动画。

first argument is for the animation enter, and 0 is for no animation.

和当你离开你的第二个活动的动画:

And for an animation when you leave your second activity :

@Override
public void finish() {
    super.finish();
    overridePendingTransition(R.anim.enterAnim, R.anim.leaveAnim);
}

这篇关于在滑到另一个XML布局按钮被点击时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆