我有一个包含一些视图的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
动画仅适用于添加,删除或更改视图的可见性!!!
答案 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)
您可以查看http://developer.android.com/reference/android/animation/LayoutTransition.html和方法http://developer.android.com/reference/android/animation/LayoutTransition.html#setAnimator(int,android.animation.Animator)来检查如何自定义布局更改动画