0

我正在使用一个图像和 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 回答