2014-01-21 31 views
0

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

enter image description here

现在,当我触摸到地图的标记,它显示的RelativeLayout(呼叫标记标题中的图片),并向上滑动效果很好的动画,不过,我滑下的代码并不能正常工作,因为它从屏幕顶部下来。我的代码是这样的:

  • 这是它隐藏的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文件,现在它的工作错误:

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

回答

5

你必须找出一种方法来计算地图的高度,并从动画开始位置减少。这样,动画就从当前位置开始,相对于屏幕的顶部。

做到这一点的另一种方法是巧妙的布局技巧。

下面是一些示例代码,介绍如何使用FrameLayout将LinearLayout覆盖在Map视图上。您将透明视图权重设置为1,以便当您将TextView切换到GONE时,它将展开以填充空间。为了动画这个变化,将animateLayoutChanges="true"添加到封闭的视图中。

实施例:

<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> 
+1

我使用的第二选项和它工作得很好。非常感谢!! :D – Yeray

+0

很高兴它的工作! –