动画的RelativeLayout滑下去 [英] Animation in RelativeLayout to slide down

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

问题描述

我需要帮助动画一个RelativeLayout的。接下来的图像解释如何为我的aplication:

I need help to animate a RelativeLayout. The next image explain how is my aplication:

现在,当我触摸到地图的标记,它会显示一个RelativeLayout的(调用标记标题在图片)和动画向上滑动效果很好,但是,我的code滑下不能很好地工作因为它从屏幕上方下来。我的code是这样的:

Now, when I touch a marker of a map, it displays a RelativeLayout (call Marker Title in the picture) and the animation to slide up works well, however, my code to slide down doesn't work well because it get down from top of the screen. My code is this:


  • 这是code在那里隐藏了RelativeLayout的:

  • This is the code where it hides the RelativeLayout:

 public void hideSlideUp() { 
    RelativeLayout slideLayout;
    slideLayout = (RelativeLayout) findViewById(R.id.sliding_up);

    if (slideLayout.getVisibility() != View.INVISIBLE) {
        Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
        slideLayout.startAnimation(slide);
        slideLayout.setVisibility(View.INVISIBLE);
     }
}


  • 动画xml文件,现在它的工作错了:

  • Animation xml file, now it's work wrong:

    <set xmlns:android="http://schemas.android.com/apk/res/android">
      <translate 
          android:fromXDelta="0" 
          android:fromYDelta="-1000" 
          android:duration="1000" />
    </set>
    


  • 推荐答案

    您不得不想出一个办法来计算地图的高度,并减少从动画开始位置。这样一来,在动画开始于它的当前的位置,相较于屏幕的顶部。

    You'd have to figure out a way to calculate the height of your map and reduce that from the animation start position. That way, the animation starts at its current location, vs the top of the screen.

    另一种方式来做到这一点,是一个布局巧妙伎俩。

    Another way to do this, is a clever layout trick.

    下面,是你将如何在使用的FrameLayout您的地图视图层一个的LinearLayout一些示例code。您可以设置透明视窗的重量为1,这样,当你切换到TextView的消失了,它扩展,以填补空间。为了这个动画更改,添加 animateLayoutChanges =真正的来封闭意见。

    Below, is some sample code of how you would layer a LinearLayout over your Map view using a FrameLayout. You set the transparent view weight to 1, so that when you toggle the TextView to GONE, it expands to fill the space. In order to animate this change, add animateLayoutChanges="true" to the enclosing views.

    例如:

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <Map
            ...
        />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true" >
            <View
                android:id="@+id/transparentViewThatExpandsWhenTextIsGone"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
            <TextView
                android:id="@+id/textViewToToggle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone" />
        </LinearLayout>
    </FrameLayout>
    

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

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