0

我在顶部位置有一个布局,并且此视图隐藏第一次。我将以编程方式上下滑动动画。我编写的代码和此代码工作完美第一次 这里是向上/向下滑动动画无法在第二次正确工作

public void cutomTabDropDownAnimation(LinearLayout view, boolean isSlideDown) { 
    TranslateAnimation animate; 
    if (isSlideDown) { 
     animate = new TranslateAnimation(
       0, 
       0, 
       0, 
       view.getHeight()); // toYDelta 
    } else { 
     animate = new TranslateAnimation(
       0, 
       0, 
       view.getHeight(),     
       0); // toYDelta 
    } 


    animate.setDuration(300); 
    animate.setFillAfter(true); 
    animate.setInterpolator(new BounceInterpolator()); 
    view.setAnimation(animate); 
    if (isSlideDown) 
     view.setVisibility(View.VISIBLE); 
    else 
     view.setVisibility(View.GONE); 


} 

在第二次,第一种观点表明,然后开始动画,但不正确的,查看隐藏。 下面是一个XML文件源

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 

android:id="@+id/myCoordinator" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#f2f2f2"> 



<LinearLayout 
    android:id="@+id/customTabLayout" 
    android:layout_width="match_parent" 
    android:layout_height="49dp" 
    android:background="#ffffff" 
    android:orientation="vertical" 
    android:visibility="gone"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="48dp"> 


     <View 
      android:id="@+id/view" 
      android:layout_width="1dp" 
      android:layout_height="match_parent" 
      android:layout_centerInParent="true" 
      android:background="@color/colorPrimary" 

      /> 

     <TextView 
      android:id="@+id/firstTab" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignEnd="@+id/view" 
      android:layout_alignParentTop="true" 
      android:layout_alignRight="@+id/view" 
      android:gravity="center" 
      android:text="@string/u_four_tab_1" 
      android:textColor="#405a97" 
      android:textSize="16dp" /> 

     <TextView 
      android:id="@+id/secondTab" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignLeft="@+id/view" 
      android:layout_alignParentTop="true" 
      android:layout_alignStart="@+id/view" 
      android:gravity="center" 
      android:text="@string/u_four_tab_2" 
      android:textColor="#d4d4d4" 
      android:textSize="16dp" 

      /> 

    </RelativeLayout> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="#801d7aed" /> 
</LinearLayout> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/nestedScrollview" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/customTabLayout"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false" /> 
</android.support.v4.widget.NestedScrollView> 

<LinearLayout 
    android:id="@+id/empty_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="16dp" 
    android:layout_marginRight="16dp" 
    android:layout_marginTop="40dp" 
    android:gravity="top|center" 
    android:orientation="vertical" 
    android:visibility="gone"> 

    <TextView 
     android:id="@+id/empty_layout_txt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="@string/u_empty_package" 
     android:textColor="#808080" 
     android:textSize="16dp" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="46dp" 
     android:background="@mipmap/package_grey" /> 
</LinearLayout> 

我的意思是在XML customTabLayout线性布局file.How我能解决这个问题?

回答

0

我认为是什么导致了奇怪的行为是你的这部分代码:

if (isSlideDown) 
    view.setVisibility(View.VISIBLE); 
else 
    view.setVisibility(View.GONE); 

您需要设置结束动画后,或者启动(根据上下文)之前,你的观点的知名度

animate.setAnimationListener(new AnimationListener() {  
    @Override 
    public void onAnimationStart(Animation animation) { 
     // TODO Auto-generated method stub 
if (isSlideDown){ 
     view.setVisibility(View.VISIBLE); 
} 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 
     // TODO Auto-generated method stub 
    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 

    if (!isSlideDown){ 
     view.setVisibility(View.GONE); 
} 

    } 
}); 
+0

我改变了,但没有别的@Jaja – BekaKK

0

更改为INVISIBLE而不是GONE。

试试这个:

if (isSlideDown) 
    view.setVisibility(View.VISIBLE); 
else 
    view.setVisibility(View.INVISIBLE); 
相关问题