1

ボタンのグループがスライドインおよびスライドアウトするアニメーションを作成しようとしていますが、1 つの問題に苦労しています。現在のアニメーションは正しく動いていますが、画面の一番左からスライドアウトしています。これを表示するために使用されるボタンはどこにありますか。このグループがこれをスライドしているため、アニメーション全体の見栄えが悪くなります。

私が達成したいのは、ボタンがある場所からアニメーションを開始するマージンまたは同様のものを追加することです。

私はそれを次のようにしたい:

マージン

つまり、これら 3 つの画像は、画面の一番左からではなく、この白い線から表示され始めます。

onCreateすべてが起こっている主な活動:

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        image1 = (LinearLayout)findViewById(R.id.imageLayout);
        button = (Button)findViewById(R.id.buttonShow);

        animationSlideInLeft = AnimationUtils.loadAnimation(this, 
                R.anim.push_right_in);
        animationSlideOutRight = AnimationUtils.loadAnimation(this, 
                R.anim.push_left_out);
        animationSlideInLeft.setDuration(1000);
        animationSlideOutRight.setDuration(1000);
        animationSlideInLeft.setAnimationListener(animationSlideInLeftListener);
        animationSlideOutRight.setAnimationListener(animationSlideOutRightListener);

        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v)
            {
                if(v == button)
                {
                    if(!on)
                    {
                        curSlidingImage = image1;
                        image1.startAnimation(animationSlideInLeft);
                        image1.setVisibility(View.VISIBLE);
                        on = true;
                    }
                    else
                    {
                        image1.startAnimation(animationSlideOutRight);
                        image1.setVisibility(View.INVISIBLE);
                        on = false;
                    }
                }
            }
        });

    }

アニメーション ファイル:

push_right_in

<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="300"
        android:fromXDelta="-100%p"
        android:toXDelta="0" />

    <alpha
        android:duration="300"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>

push_left_out

<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="300"
        android:fromXDelta="0"
        android:toXDelta="-100%p" />

    <alpha
        android:duration="300"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

</set>

main.xml

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

    <Button
        android:id="@+id/buttonShow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Btn" />

    <LinearLayout
        android:id="@+id/imageLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible" >

        <ImageView
            android:id="@+id/image1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/image2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/image3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon" />
    </LinearLayout>

</LinearLayout>
4

2 に答える 2

0

親の相対レイアウトにパディングを追加できます。この場合、アニメーションはこのようなパディングから始まります

    <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="64dp">
于 2015-12-08T13:09:53.030 に答える