2017-08-10 10 views
1

3つのカテゴリに属する​​情報を表す3つのテキストビューがあります。私はまた、各カテゴリーのタイトルを表す3つのテキストビューを持っています。Text Viewで滑らかなslide_up/downアニメーションを作成する方法は?

これらのテキストビューは互いに拘束されています(テキストビューAタイトルはテキストビューB情報の上に拘束されたテキストビューAの情報の上に拘束されています)。テキストビューのタイトルをクリックしたときに、対応するテキストビュー情報が滑り落ちるとの情報が表示されるように、私は、コードを書かれている

enter image description here

:次のようになります。

ここで私の問題は、テキストビューBの情報がデータで入力されたときに、テキストビューCのタイトルが表示され、テキストビューBの情報の最後が表示されますが、テキストビューは正しいですが、私が望んでいないぎこちない動きです)。

enter image description here

タイトルを再度クリックするscroll_upがトリガされますが、テキストビューCと似て、2秒(slide_downの時間)がテキストビューB情報がいっぱいとテキストビュー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のタイトルが後退するまでの時間を待って実行可能なスレッド(あなたがアニメーションの長さを設定した時間)を使用して、それを迅速に修正を与えるために管理しました。これにより、テキストビューCのタイトルが元の位置にスナップしてリストがスクロールダウンされる前に、テキストビューBのコンテンツ時間が完全に短縮されます。

テキストビューCのタイトルはまだ戻ってスナップぎくしゃくした運動を持っていますが、それは実際にここで

が新しいメソッドですよさそうだ。

if(OverallTextViewContent.isShown()){ 

     slide_up(this, OverallTextViewContent); 

     view.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       OverallTextViewContent.setVisibility(View.GONE); 
      } 
     }, 500); 
    } 
関連する問題