0

1 つの画像と framelayout(conatining button and linearLayout) を使用してリストビューを実装しています。画像をクリックすると linearLayout をアニメーション化したいと考えています。出来ますか?次のコードを書きました。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@drawable/icon" />

<FrameLayout
    android:id="@+id/frame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Button" />

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/a"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/from_user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000" />

        <TextView
            android:id="@+id/from_user_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#000000" />
    </LinearLayout>
</FrameLayout>

私を助けてください。

4

1 に答える 1

0

imageview の onClickListener で animate メソッドを呼び出すことができます..

ivmg.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View arg0, MotionEvent arg1) {
                    // TODO Auto-generated method stub

                    startLayoutAnimation(myLayout);
                    return false;
                }
            });

メソッドを次のように定義します...

public void startLayoutAnimation(LinearLayout mLayout)
        {
            System.out.println("Inside startAnimation()");
            Animation scaleAnim = new ScaleAnimation(0, 2, 0, 2);
            scaleAnim.setDuration(5000);
            scaleAnim.setRepeatCount(1);
            scaleAnim.setInterpolator(new AccelerateInterpolator());
            scaleAnim.setRepeatMode(Animation.REVERSE);

        /*  Animation rotateAnim = new RotateAnimation(0, 360);
            rotateAnim.setDuration(5000);
            rotateAnim.setRepeatCount(1);
            rotateAnim.setInterpolator(new AccelerateInterpolator());
            rotateAnim.setRepeatMode(Animation.REVERSE);*/

            Animation rotateAnim = new RotateAnimation(0, 360, Animation.ABSOLUTE, Animation.ABSOLUTE, Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF);
            rotateAnim.setDuration(5000);
            rotateAnim.setRepeatCount(1);
            rotateAnim.setInterpolator(new AccelerateInterpolator());
            rotateAnim.setRepeatMode(Animation.REVERSE);

            AnimationSet animationSet = new AnimationSet(true);
            animationSet.addAnimation(scaleAnim);
            animationSet.addAnimation(rotateAnim);

            mLayout.startAnimation(animationSet);
        }
   }

レイアウトのアニメーション化はまだ試していません。したがって、機能するかどうかを確認する必要があります。それが役に立てば幸い

于 2012-11-07T06:43:28.477 に答える