在对象动画期间分层视图

时间:2015-03-07 06:42:28

标签: android android-layout layout objectanimator

我有一个相对布局,其中LinearLayout作为子视图组,按钮作为子视图。所以当我按下按钮时,线性布局会从屏幕上掉下来,但它会在按钮下面,我希望它能够翻过按钮。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/relative"

>

    <LinearLayout
        android:layout_width="365dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/linearLayout"
        android:background="@drawable/background">


        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:hint="Name"
            android:ems="10"
            android:id="@+id/editText"

            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/editText"
            android:layout_alignRight="@+id/editText"
            android:layout_alignEnd="@+id/editText"
            >
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Male"
                android:id="@+id/radioButton"
                android:layout_below="@+id/linearLayout"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Female"
                android:id="@+id/radioButton2"
                android:layout_below="@+id/linearLayout"
                android:layout_toRightOf="@+id/radioButton"
                android:layout_toEndOf="@+id/radioButton" />
        </RadioGroup>

    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Signup"
        android:id="@+id/button"

        android:layout_gravity="center"
       android:translationZ="1dp"
        android:layout_below="@+id/linearLayout"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="45dp" />

Layout

我的java代码是:

public class MainActivity extends Activity {
ValueAnimator va;
LinearLayout linearLayout;
Button button;
ValueAnimator objectAnimator;
RelativeLayout relative;
boolean b=false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   linearLayout=(LinearLayout) findViewById(R.id.linearLayout);
    button=(Button) findViewById(R.id.button);
    setbuttonclick();
    relative=(RelativeLayout) findViewById(R.id.relative);
    relative.bringChildToFront(linearLayout);

}

public void setbuttonclick()
{
    button.setOnClickListener(new View.OnClickListener() {
        @Override

        public void onClick(View v) {





            if(b==false) {
                objectAnimator = ObjectAnimator.ofFloat(linearLayout,        "TranslationY", 2600f);
                objectAnimator.setDuration(1000);
                objectAnimator.setInterpolator(new AnticipateOvershootInterpolator());
                objectAnimator.start();

                b=true;
            }

            else {
                objectAnimator = ObjectAnimator.ofFloat(linearLayout, "TranslationY", 50f);
                objectAnimator.setDuration(1000);
                objectAnimator.setInterpolator(new AnticipateOvershootInterpolator());
                objectAnimator.start();

                b=false;
            }


        }
    });
}

}

What is happening

0 个答案:

没有答案