动画相对布局 [英] Animating Relativelayout

查看:65
本文介绍了动画相对布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遵循了屏幕的XML结构.我希望我的ID为lageLandingView的相对布局在单击某些按钮时向上滑动,并显示ID为tripalRootView的视图RelativeLayout将从底部向上滑动,因为tripalLandingView的Fill_Parent设置为高度和宽度,因此tripRootRootView必须位于覆盖整个视图的tripLandLingingView下方屏幕.我该怎么办?

I have got following XML structure of my screen. I want my Relative Layout with id journeyLandingView to get slide up upon click on some button and show view RelativeLayout with id journeyRootView which will slide up from bottom since journeyLandingView have Fill_Parent set as height and width so journeyRootView must be below journeyLandingView that is covering the whole screen. How can I do that?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <RelativeLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/journeyLandingView">   
    </RelativeLayout>

    <RelativeLayout android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:id="@+id/journeyRootView"
        android:background="@drawable/root_layer">

    </RelativeLayout>
</LinearLayout>

推荐答案

我最终使用RelativeLAYOUT而不是LINEARLAYOUT作为父元素,然后使用以下代码进行动画处理.

I ended up using RelativeLAYOUT instead of LINEARLAYOUT as a parent element and than used following code to animate.

TranslateAnimation slide = new TranslateAnimation(0, 0, 0, -1*Methods.screenHeight(this));   
             slide.setDuration(1000);   
             slide.setFillAfter(true);   
             journeyLandingView.startAnimation(slide); 
             slide = new TranslateAnimation(0, 0, Methods.screenHeight(this), 0);   
             slide.setDuration(1000);   
             slide.setFillAfter(true);   
             journeyRootView.startAnimation(slide);

public static int screenHeight(Context ctx) {
        DisplayMetrics displaymetrics = new DisplayMetrics();
        ((Activity) ctx).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);                 
        return displaymetrics.heightPixels;
    }

这篇关于动画相对布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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