将带有动画的 layout_weight 从 0.3 扩展到 0.8

我有一个片段滑动到屏幕高度的 0.3...现在我想在按钮上将它从 0.3 动画到 0.8。但是怎么做呢?我可以为 layout_weight 设置动画吗?单击按钮后我需要显示更多信息,为什么要升高高度。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" />




婷婷同学_
浏览 171回答 1
1回答

眼眸繁星

您可以通过使用 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() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onAnimationUpdate(ValueAnimator animation) {&nbsp; &nbsp; &nbsp; &nbsp; float value = (float) animation.getAnimatedValue();&nbsp; &nbsp; &nbsp; &nbsp; LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) details.getLayoutParams();&nbsp; &nbsp; &nbsp; &nbsp; params.weight = value;&nbsp; &nbsp; &nbsp; &nbsp; details.setLayoutParams(params);&nbsp; &nbsp; }});现在,您可以随时调用animator.start()从 30% 高度到 80% 高度的动画视图。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java