我有这个布局来测试一些Animations
.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/frame1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00ff00"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1"/>
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2"/>
</LinearLayout>
<LinearLayout
android:id="@+id/frame2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#0000ff">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_style"/>
</LinearLayout>
</LinearLayout>
我想要实现的是list
LinearLayout中的 ListViewframe2
应该增长到屏幕顶部,而 LinearLayoutframe1
缩小。
这可以很容易地用ObjectAnimator
andAnimatorSet
像这样来完成:
ObjectAnimator animframe1 = ObjectAnimator.ofInt(frame1, "bottom", 0);
ObjectAnimator animframe2 = ObjectAnimator.ofInt(frame2, "top", 0);
ObjectAnimator listview = ObjectAnimator.ofInt(list, "bottom", frame2.getBottom());
AnimatorSet set = new AnimatorSet();
set.setDuration(1000L);
set.playTogether(animframe1, animframe2, listview);
set.start();
我所做的是操纵视图的top
和bottom
属性以产生增长/收缩效果。
它像我想要的那样工作,但有一个缺陷:当 ListView 增长时,其他项目(在那里)是不可见的。房间应该在那里,但是只有在动画后单击 ListView 时才会显示其他项目。
我怎么能说 ListView 在动画运行时应该重新加载附加项目?
我试图打电话list.invalidate()
,AnimationUpdateListener
但没有成功。如果我打电话list.requestLayout()
,就不会有动画。