2017-05-08 40 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

相关问题