Kan*_*pai 0 java animation android
我有一个片段可以滑动到屏幕高度的 0.3...现在我想在按钮上将其从 0.3 动画到 0.8。但怎么办呢?我可以为布局权重设置动画吗?单击按钮后我需要显示更多信息,说明为什么要升高高度。objectAnimator 不起作用。
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:gravity="bottom">
<LinearLayout
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:animateLayoutChanges="true"
android:background="@drawable/shape_details"
android:clickable="true"
android:orientation="vertical"
android:padding="15dp"
android:paddingBottom="32dp"
android:paddingTop="32dp">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text=""
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_weight=".1"
android:src="@drawable/time" />
<TextView
android:id="@+id/time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".9"
android:text="TextView"
android:textColor="@android:color/darker_gray"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
您可以通过使用 aValueAnimator
将 afloat
从 0.3 动画化到 0.8,然后使用 anAnimatorUpdateListener
更新weight
详细信息视图中的值来实现此目的LayoutParams
。
LinearLayout details = findViewById(R.id.details);
ValueAnimator animator = ValueAnimator.ofFloat(0.3f, 0.8f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (float) animation.getAnimatedValue();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) details.getLayoutParams();
params.weight = value;
details.setLayoutParams(params);
}
});
Run Code Online (Sandbox Code Playgroud)
animator.start()
现在,只要您想要将视图从 30% 高度动画化到 80% 高度,您就可以调用。
归档时间: |
|
查看次数: |
228 次 |
最近记录: |