在滑到另一个XML布局按钮被点击时 [英] Slide in another XML layout when button is clicked
问题描述
我有一个的main.xml
布局文件和我的Java code,我做从主采取了一些计算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屋!