5

カスタム コンテンツを表示するためにカスタム アダプターを使用するリスト ビューがあります。そのレイアウトは次のとおりです。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <ImageView
            android:id="@+id/itemimage"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="5"
            android:scaleType="fitCenter"/>
        <TextView
            android:id="@+id/itemdescription"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="10dp"
            android:textSize="16sp"
            android:layout_weight="1"/>
    </LinearLayout>    
    <TextView
            android:id="@+id/itemtext"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="TEXT CONTENT"
            android:layout_weight="1"/>
</LinearLayout>    

リストビューには、ids itemimage と item description を含むビューのみを表示し、itemtext は非表示にしたいと思います。アイデアは、リストの各アイテムに onclicklistener を配置して、そのアイテムを展開して itemtext コンテンツを表示することです。各アイテムを展開/折りたたむために Tweening アニメーションを使用する必要があることはわかっていますが、その方法がわかりません。

誰でも私を助けることができますか?さらにコード スニペットが必要な場合は、お気軽にお問い合わせください。

前もって感謝します。

4

2 に答える 2

8

そのために、余白を負の値にアニメートしてアイテムを非表示にする Animation クラスを作成しました。

アニメーションは次のようになります。

public class ExpandAnimation extends Animation {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    super.applyTransformation(interpolatedTime, t);

    if (interpolatedTime < 1.0f) {

        // Calculating the new bottom margin, and setting it
        mViewLayoutParams.bottomMargin = mMarginStart
                + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);

        // Invalidating the layout, making us seeing the changes we made
        mAnimatedView.requestLayout();
    }
}
}

私のブログ投稿に、このアニメーションのサンプル アプリ全体があります。

于 2012-05-14T13:56:25.247 に答える