Android - 用于调整视图大小的LayoutChange Animation

时间:2014-10-15 13:31:03

标签: android

我有一个包含一些视图的LinearLayout ......

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:id="@+id/carSelectLayout"
    android:orientation="vertical"
    android:weightSum="100"
    android:background="#C9C9C9">

    <LinearLayout
        android:id="@+id/LogoFragment"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="25"
        android:orientation="vertical" />
    <LinearLayout
        android:id="@+id/CarCategoryFragment" 
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="50"
        android:orientation="vertical"/>

</LinearLayout>

有没有办法用动画改变视图权重?类似于LayoutChanges动画......

编辑:

LayoutChanges动画仅适用于添加,删除或更改视图的可见性!!!

2 个答案:

答案 0 :(得分:2)

您可以使用ValueAnimator,然后在以编程方式更改布局参数的位置添加更新侦听器。

    ValueAnimator animator = ValueAnimator.ofInt(start, end);

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100);
            lp.weight = value;
            animatedView.setLayoutParams(lp);
        }
    });
    mAnimator.start();

答案 1 :(得分:1)