2017-08-10 124 views
1

我有3个文本视图代表属于3个类别的信息。我还有3个其他文本视图代表每个类别的标题。如何在文本视图上制作更平滑的滑动上/下动画?

这些文本视图被约束彼此抵靠(文字标题被上述文本视图信息,该约束的文本视图B标题,其被上述文本视图B信息约束约束)。看起来是这样的:

enter image description here

,这样点击文本视图标题时,相应的文本查看信息滑下,并显示信息我已经写代码。

这里我的问题是,例如,当文本视图B信息填充数据时,文本视图C标题将出现在文本视图B信息的末尾即将出现的位置,但是在突然和粗糙的移动中文本视图仍然是正确的,这是我不想要的生涩运动)。 2秒(该slide_down的时间)后的文本视图B信息被填充并且是长毛绒上述文本视图C标题:

enter image description here

相若方式,当标题被再次点击scroll_up被触发但是文本视图C标题直接出现在传送中的文本视图B信息下。然后发生滑动和文本经过文本视图C标题:

enter image description here

有没有什么办法,使文本查看文本查看已滑动,将滑块的滑动运动被推向下方up或slide_down,而不是正在发生的这个传送?

我一直在摆弄现在用了一段代码,我坚持。

调用动画的方法:

public void ShowWeekly(View view) { 

    if(WeeklyTextView.isShown()){ 
     slide_up(this, WeeklyTextView); 
     WeeklyTextView.setVisibility(View.GONE); 
    } 
    else{ 
     WeeklyTextView.setVisibility(View.VISIBLE); 
     slide_down(this, WeeklyTextView); 
    } 
} 

的slide_up的xml:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 

android:fillAfter="false"> 
<scale 
    android:duration="2000" 
    android:fromXScale="1.0" 
    android:fromYScale="1.0" 
    android:interpolator="@android:anim/test" 
    android:toXScale="0.0" 
    android:toYScale="0.0" /> 

Slide_down XML:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 

android:fillAfter="true"> 
<scale 
    android:duration="200" 
    android:fromXScale="1.0" 
    android:fromYScale="0.0" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:toXScale="1.0" 
    android:toYScale="1.0" /> 

文本视图是滚动视图中的约束布局。以下是文字观点:

<ScrollView 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="16dp" 
    android:id="@+id/scroll" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/OverallButton"> 

    <android.support.constraint.ConstraintLayout 
     android:id="@+id/constraint" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toBottomOf="@id/OverallButton" 
     > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20dp" 
      android:id="@+id/OverallTextView" 
      android:text="Overall Statistics\n" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="parent" 
      android:onClick="ShowDistance" 
     /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/OverallTextViewContent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/OverallTextView" 
      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Weekly Statistics\n" 
      android:textSize="20dp" 
      android:id="@+id/WeeklyTextView" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/OverallTextViewContent" 
      android:onClick="ShowWeekly" 
      /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/WeeklyTextViewContent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/WeeklyTextView" 
      /> 



     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Best Statistics\n" 
      android:textSize="20dp" 
      android:id="@+id/BestTextView" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/WeeklyTextViewContent" 
      android:onClick="ShowBest" 
      /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/BestTextViewContent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/BestTextView" 
      /> 

</android.support.constraint.ConstraintLayout> 

</ScrollView> 

回答

0

我设法通过使用一个可运行的线程等待文本视图C标题移回之前的一段时间(您设置的动画所需的时间),给它一个速战速决。这使文本视图B内容时间完全缩小,然后文本视图C标题在列表向下滚动之前回到其原始位置。

文本视图C标题仍然有返回时的卡生涩的运动,但它实际上看起来不错

下面是新方法:

if(OverallTextViewContent.isShown()){ 

     slide_up(this, OverallTextViewContent); 

     view.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       OverallTextViewContent.setVisibility(View.GONE); 
      } 
     }, 500); 
    }