1

私はいくつかをテストするためにこのレイアウトを持っています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>

私が達成したいのは、LinearLayout の ListViewlistframe2画面の上部まで成長し、LinearLayoutframe1が縮小することです。

ObjectAnimatorこれは、次のAnimatorSetように と を使用して非常に簡単に実行できます。

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プロパティを操作して、拡大/縮小効果を持たせることです。

それは私が望むように動作しますが、1 つの欠点があります: ListView が成長している間、(そこにある) 追加の項目は表示されません。部屋はそこにあるはずですが、アニメーションの後に ListView をクリックした場合にのみ、追加の項目が表示されます。

アニメーションの実行中に追加のアイテムをリロードする必要があることを ListView に伝えるにはどうすればよいですか?

電話をかけようとしlist.invalidate()ましたAnimationUpdateListenerが、成功しませんでした。私が呼び出すlist.requestLayout()と、アニメーションはありません。

4

1 に答える 1

1

私が見逃したのは、プロパティが変更されたheight後に ListViewを設定することです。topこれがないと、ListView は同じ古い高さを保持します。これが、追加の項目が表示されない理由です。

CustomListView クラスのセッターを追加する必要がないため、ValueAnimator に切り替えましたheight

コードは次のようになります。

public void animateListHeight() {
    PropertyValuesHolder topList = PropertyValuesHolder.ofInt("top", mListView.getTop(), 5);

    ValueAnimator animList = ValueAnimator.ofPropertyValuesHolder(topList);
    animList.setDuration(300L);

    AnimatorUpdateListener listUpdater = new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int top = ((Integer)animation.getAnimatedValue("top")).intValue();
            mListView.setTop(top);
            ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) mListView.getLayoutParams();
            params.height = mListView.getBottom() - top;
            mListView.setLayoutParams(params);
        }
    };

    animList.addUpdateListener(listUpdater);
    animList.start();
}
于 2014-04-29T08:06:11.357 に答える