2017-05-08 88 views
0

我正在創建具有searchBar by this lib屏幕的應用程序。 我的活動佈局是這樣的:ConstraintLayout中的Animate LayoutParams更改

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<android.support.constraint.ConstraintLayout 
     android:id="@+id/wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:animateLayoutChanges="true"> 

    <TextView 
      android:id="@+id/title" 
      android:textColor="@color/colorPrimary" 
      android:text="@string/mainScreenTitle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:textAlignment="center" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      android:paddingTop="100dp"/> 

    <com.arlib.floatingsearchview.FloatingSearchView 
      android:id="@+id/searchView" 
      android:layout_width="0dp" 
      android:layout_height="50dp" 
      android:layout_marginTop="100dp" 
      android:animateLayoutChanges="true" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/title"/> 

</android.support.constraint.ConstraintLayout> 

</RelativeLayout> 

在那裏,我必須FloatingSearchingView移動到屏幕和變化高度的頂部,例如500dp - 這樣的:

app:layout_constraintTop_toTopOf="parent" 
android:layout_height="500dp" 

,我稍後會移動它回到並改變高度再次默認值

app:layout_constraintTop_toBottomOf="@+id/title" 
android:layout_height="50dp" 

問題是,我必須動畫。我花了很多時間尋找解決方案,但不幸的是我沒有找到任何東西。

回答

0

嘗試使用Animation類這樣的:

Animation animation = new Animation() { 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     LayoutParams params = yourView.getLayoutParams(); 

     // modify your layout params here 

     yourView.setLayoutParams(params); 
    } 
}; 
animation.setDuration(500); // in ms 
yourView.startAnimation(animation); 
+0

我做params.topToBottom = -1和params.topToTop = R.id.wrapper內applyTransformation方法,但它仍然沒有動畫:C – Qiteq

相關問題