3

私はしばらくの間インターネットを探し回っていましたが、アニメーションの問題に対する実行可能な解決策を見つけることができませんでした。

アイテムの1つをクリックすると、下からより多くの情報がアニメーション化され、数行の追加情報が表示されるリストビューがあります。これは、これらのリスト項目に使用しているXMLファイル内にあるlinearlayoutです。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >




<LinearLayout
    android:id="@+id/friendActivityList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/friendInfo"
    android:background="@color/grey"
    android:orientation="vertical"
    android:visibility="gone" >

    <RelativeLayout
        android:id="@+id/RelativeLayout04"
        android:layout_width="match_parent"
        android:layout_height="@dimen/freind_activity_list_height" >

        <ImageView
            android:id="@+id/ImageView04"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_margin="5dp"
            android:src="@drawable/logo_d" />

        <TextView
            android:id="@+id/TextView04"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/ImageView04"
            android:text="TextView"
            android:textColor="@color/black"
            android:textSize="17dp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/RelativeLayout03"
        android:layout_width="match_parent"
        android:layout_height="@dimen/freind_activity_list_height" >

        <ImageView
            android:id="@+id/ImageView03"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_margin="5dp"
            android:src="@drawable/logo_d" />

        <TextView
            android:id="@+id/TextView03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/ImageView03"
            android:text="TextView"
            android:textColor="@color/black"
            android:textSize="17dp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/RelativeLayout02"
        android:layout_width="match_parent"
        android:layout_height="@dimen/freind_activity_list_height" >

        <ImageView
            android:id="@+id/ImageView02"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_margin="5dp"
            android:src="@drawable/logo_d" />

        <TextView
            android:id="@+id/TextView02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/ImageView02"
            android:text="TextView"
            android:textColor="@color/black"
            android:textSize="17dp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="@dimen/freind_activity_list_height" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_margin="5dp"
            android:src="@drawable/logo_d" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/imageView1"
            android:text="TextView"
            android:textColor="@color/black"
            android:textSize="17dp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/RelativeLayout01"
        android:layout_width="match_parent"
        android:layout_height="@dimen/freind_activity_list_height">

        <ImageView
            android:id="@+id/ImageView01"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_margin="5dp"
            android:src="@drawable/logo_d" />

        <TextView
            android:id="@+id/TextView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/ImageView01"
            android:text="TextView"
            android:textColor="@color/black"
            android:textSize="17dp" />
            </RelativeLayout>
        </LinearLayout>






        <RelativeLayout
            android:id="@+id/friendInfo"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:background="@drawable/bg_list_item_n" >

    <ImageView android:id="@+id/imgCompany"
        android:layout_marginLeft="5dp" 
        android:layout_centerVertical="true"
        android:layout_width="60dp"
        android:src="@drawable/ic_launcher"
        android:scaleType="centerInside" 
        android:layout_alignParentLeft="true"
        android:layout_height="50dp">
    </ImageView>



    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:layout_toRightOf="@id/imgCompany"
        android:background="@android:color/transparent"
        android:gravity="left|center"
        android:orientation="vertical"
        android:paddingLeft="5dp" >

            <TextView android:id="@+id/lblCompanyName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textStyle="bold"
                android:textSize="13dp"
                android:text="Company Name">
            </TextView>

            <TextView android:id="@+id/lblReawrdDesc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="13dp"
                android:text="Reawrd Description">
            </TextView>

            <TextView android:id="@+id/lblScores"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:textSize="13dp"
                android:singleLine="true"
                android:text="My Score: 13434 | Top Score: 344425">
            </TextView>

        </LinearLayout>

    </RelativeLayout>

    </RelativeLayout>

これのほとんどは、アニメーションを正しく機能させるためのプレースホルダー情報です。アニメーションに使用しているコードは次のとおりです。

    listviewFriends.setOnItemClickListener(new OnItemClickListener() {//this is the listView that im animating inside of

        public void onItemClick(AdapterView<?> parent, View view,final int pos, long id) {
            Log.v("ListItemClicked", "this position was clicked: "+pos);
            if(friendInfoList != null){
                friendInfoList.clearAnimation();//this is the new view that gets animated and is supposed to push everything below it out of the way
                friendInfoList.setVisibility(View.GONE);
            }
            friendInfoList = (LinearLayout) view.findViewById(R.id.friendActivityList);
            friendInfoList.setVisibility(View.VISIBLE);
            friendInfoList.startAnimation(infoAnim);

        }
    });

    infoAnim = new TranslateAnimation(0,0, -150, 0);//this is the animation im using
    infoAnim.setDuration(1000);
    infoAnim.setFillAfter(true);

この結果ではありません。リストビューアイテムをクリックすると、アニメーション化されるはずのビューが最後に占めるスペース全体が白くなり、ビューは上から下にアニメーション化されます。場所は正しいですが、アニメーション化してその下のすべてを邪魔にならないようにプッシュしたいのですが、代わりにすべてを即座に邪魔にならないようにプッシュしてから、そのスペースを埋めるためにアニメーション化します。

アニメーション中にすぐにではなく、すべてを邪魔にならないようにする方法はありますか?この効果を達成することさえ可能ですか?どんな助けでも大歓迎です。

また、他のビューの上に単純にアニメーション化する方法は知っていますが、実際にすべてを邪魔にならないようにするために必要です。

4

1 に答える 1

4

これの秘訣は、独自の Animation サブクラスを作成することです。

public class ExpandAnimation extends Animation
{
    private int _targetHeight;
    private View _view;
    private boolean _down;

    public ExpandAnimation(View view, int targetHeight)
    {
        _view = view;
        _targetHeight = targetHeight;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t)
    {
        int newHeight;
        if(_down)
        {
            newHeight = (int) (_targetHeight * interpolatedTime);
        }
        else
        {
            newHeight = (int) (_targetHeight * (1 - interpolatedTime));
        }

        _view.getLayoutParams().height = newHeight;
        _view.requestLayout();
    }

    public ExpandAnimation expand()
    {
        _down = true;
        return this;
    }

    public ExpandAnimation collapse()
    {
        _down = false;
        return this;
    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight)
    {
        super.initialize(width, height, parentWidth, parentHeight);
    }

    @Override
    public boolean willChangeBounds()
    {
        return true;
    }
}

次に、展開する必要があるビューにそれを適用できます。

public void togglePreview()
{
    if(_expanded) _preview.startAnimation(_animation.collapse());
    else _preview.startAnimation(_animation.expand());

    _expanded = !_expanded;
    getParent().requestLayout();
}
于 2012-05-16T20:33:35.240 に答える