Android动画已禁用EditText

时间:2016-04-26 06:36:09

标签: android android-layout

我将Bounce效果添加到Linear布局。这个线性布局包含2个EditTexts和一个按钮。但是当动画完成Edittexts和Button被禁用时。我无法使用它们。我可以启用Edittexts和Button。

XML

<LinearLayout android:background="@drawable/login_grd" xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_marginTop="50dp"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <TextView
            android:textSize="55sp"
            android:gravity="center"
            android:layout_gravity="center"
            android:textColor="#fff"
            android:id="@+id/_title"
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="AFF"/>



        <Button
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="200dp"
            android:textColor="#000"
            android:background="#fff"
            android:id="@+id/animloginButton"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:text="Login"/>


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="480dp"
            android:background="@color/white"
            android:id="@+id/lnr_do_login"
            android:layout_marginTop="280dp">

            <android.support.design.widget.TextInputLayout
                android:theme="@style/TextLabel2"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="5dp"
                android:id="@+id/input_layout_username"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <EditText
                    android:textSize="16sp"
                    android:textColor="@color/black"
                    android:id="@+id/input_username"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Username" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:theme="@style/TextLabel2"
                android:id="@+id/input_layout_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp">

                <EditText
                    android:textSize="16sp"
                    android:textColor="@color/black"
                    android:inputType="textPassword"
                    android:id="@+id/input_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Password" />

            </android.support.design.widget.TextInputLayout>

            <Button
                android:textColor="#000"
                android:background="#fff"
                android:id="@+id/loginButton"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:text="Sign In"/>

        </LinearLayout>


        <TextView

            android:textColor="@color/white"
            android:layout_gravity="bottom|right"
            android:gravity="bottom|center"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:text="@string/app_name"
            android:layout_marginBottom="10dp" />

    </LinearLayout>



</LinearLayout>

LoginActivity.class

private LinearLayout lnrLoginView;
    @Override
    public void onCreate(Bundle savedInstanceState ) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.before_login_screen);

        animloginButton = (Button) findViewById(R.id.animloginButton);
        lnrLoginView = (LinearLayout) findViewById(R.id.lnr_do_login);

        TextView title = (TextView) findViewById(R.id._title);
        Typeface type = Typeface.createFromAsset(getAssets(),"fonts/title_font.ttf");
        title.setTypeface(type);

        animloginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                lnrLoginView.clearAnimation();
                TranslateAnimation translation;
                translation = new TranslateAnimation(0f, 0F, 0f, -getDisplayHeight());
                translation.setStartOffset(10);
                translation.setDuration(1000);
                translation.setFillAfter(true);
                translation.setInterpolator(new BounceInterpolator());
                lnrLoginView.startAnimation(translation);
                animloginButton.setVisibility(View.INVISIBLE);
            }

            private int getDisplayHeight() {
                DisplayMetrics metrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metrics);
                return metrics.widthPixels;
            }
        });
    }

2 个答案:

答案 0 :(得分:1)

尝试使用ObjectAnimator.onFloat代替。

 animloginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            if(lnrLoginView.getTag() instanceof Animator){
                ((Animator)lnrLoginView.getTag()).cancel();
            }
            ObjectAnimator translateY = ObjectAnimator
                    .ofFloat(target, "translationY", -transY)
                    .setDuration(1000)
            ;
            translateY.setStartDelay(10);
            translateY.setTarget(lnrLoginView);
            translateY.setInterpolator(new BounceInterpolator());
            translateY.start();
            animloginButton.setVisibility(View.INVISIBLE);
        }

        private int getDisplayHeight() {
            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            return metrics.widthPixels;
        }
    });

答案 1 :(得分:0)

使用动画侦听器在动画之前和之后制作视图。

translation.setAnimationListener(new AnimationListener() {

    @Override
    public void onAnimationStart(Animation animation) {
        //Disable the views.

    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        //Enable the views

    }
});