Android:布局“幻灯片"屏幕外? [英] Android: Layouts "slide" off the screen?

查看:96
本文介绍了Android:布局“幻灯片"屏幕外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局很像下面的布局.当前,当按下后退按钮时,红色线性布局的可见性被设置为消失.但是,我希望它可以滑出"页面.我该怎么办?

I've got a layout much like the one below. Currently when the back button is pressed the red linear layout's visibility is set to gone. However, I'd like it to "slide" up off of the page instead. How would I do this?

推荐答案

您需要使用动画.这是最上面的进/出动画:

You need to use animations. here is the top in/out animations:

在顶部

  <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="-100%" android:toYDelta="0%" android:duration="300"/>
</set>

顶部

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="0%" android:toYDelta="-100%" android:duration="600"/>
</set>

然后在您的活动中获取视图并向其应用动画,如下所示: 这是动画类型.

Then in your activity get the view and apply an animation to it like this: This are type Animation.

  mSlideInTop = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
        mSlideOutTop = AnimationUtils.loadAnimation(this, R.anim.slide_out_top);

并使用以下代码致电给他们:

and call them with this code:

header.startAnimation(mSlideOutTop);
        header.setVisibility(View.INVISIBLE);

这里的标题是一个包含我的视图的LinearLayout.如果您想使其滑入,也可以这样做.只需将幻灯片添加到动画中并使视图可见即可.

Here header is a LinearLayout wrapping my views. same thing if you want to make it slide in. just add the slide in animation and make the view visible.

这篇关于Android:布局“幻灯片"屏幕外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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