Qit*_*teq 5 animation android layoutparams android-constraintlayout
I am creating app in which there is screen with searchBar by this lib. My activity layout looks like this:
<?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>
Run Code Online (Sandbox Code Playgroud)
There i have to move FloatingSearchingView to top of screen and change height to for example 500dp - like this:
app:layout_constraintTop_toTopOf="parent"
android:layout_height="500dp"
Run Code Online (Sandbox Code Playgroud)
And later i will have to move it back and change height again to default value
app:layout_constraintTop_toBottomOf="@+id/title"
android:layout_height="50dp"
Run Code Online (Sandbox Code Playgroud)
The problem is, i have to animate it. I have spent a lot of time searching for solution but unfortunately i didnt find anything.
Alb*_*o M 14
我必须在 ConstraintLayout 内对 TextView 高度进行动画处理。
<androidx.constraintlayout.widget.ConstraintLayout
...
android:animateLayoutChanges="true"
>
<TextView
...
Run Code Online (Sandbox Code Playgroud)
我首先通知 ConstraintLayout 布局即将改变:
constraintlayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
Run Code Online (Sandbox Code Playgroud)
然后更新 textView 高度(或任何其他参数)
textView.getLayoutParams().height = 200;
textView.requestLayout();
Run Code Online (Sandbox Code Playgroud)
对于这样简单的事情,不需要设置动画师或涉及其他库。
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);
Run Code Online (Sandbox Code Playgroud)