Creating login animation like facebook android

前端 未结 2 1331
梦如初夏
梦如初夏 2021-02-09 15:56

I want to create a login page (Like facebook android app) where the userid and password EditText fields are hidden. A logo is shown on the page which animates above

相关标签:
2条回答
  • 2021-02-09 16:30

    1st The facebook image goes up so you have to translate it from current position to top

    <translate
        android:fromYDelta="0%p"
        android:toYDelta="-30%p"
        android:duration="1000" />
    

    Here android:fromYDelta is start position and android:toYDelta is end position in percentage i.e -30% and android:duration is in time i.e. 1 second

    2nd Now attach a listener to check when animation is done 3rd Now Fade in your login box

    here is the code

    MinActivity.java

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.animation.Animation;
    import android.view.animation.Animation.AnimationListener;
    import android.view.animation.AnimationUtils;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button startAnimation =(Button) findViewById(R.id.button1);
            final LinearLayout LoginBox = (LinearLayout) findViewById(R.id.LoginBox);
            LoginBox.setVisibility(View.GONE);
            startAnimation.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    Animation animTranslate  = AnimationUtils.loadAnimation(MainActivity.this, R.anim.translate);
                    animTranslate.setAnimationListener(new AnimationListener() {
    
                        @Override
                        public void onAnimationStart(Animation arg0) { }
    
                        @Override
                        public void onAnimationRepeat(Animation arg0) { }
    
                        @Override
                        public void onAnimationEnd(Animation arg0) {
                            LoginBox.setVisibility(View.VISIBLE);
                            Animation animFade  = AnimationUtils.loadAnimation(MainActivity.this, R.anim.fade);
                            LoginBox.startAnimation(animFade);
                        }
                    });
                    ImageView imgLogo = (ImageView) findViewById(R.id.imageView1);
                    imgLogo.startAnimation(animTranslate);
    
                }
            });
    
        }
    
    }
    

    And in the anim folder use these xml's

    fade.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator" >
        <alpha
            android:duration="200"
            android:fromAlpha="0.0"
            android:interpolator="@android:anim/accelerate_interpolator"
            android:toAlpha="1.0" />
    
    </set>
    

    translate.xml

    <?xml version="1.0" encoding="utf-8"?>
    <set
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fillAfter="true">
    
       <translate
            android:fromYDelta="0%p"
            android:toYDelta="-30%p"
            android:duration="1000" />
    </set>
    

    And the layout activity_main.xml

    <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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="Start Animation" />
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_launcher" />
    
        <LinearLayout
            android:id="@+id/LoginBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:orientation="vertical" >
    
            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Email ID" />
    
            <EditText
                android:id="@+id/editText2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:inputType="textPassword" />
    
            <Button
                android:id="@+id/button2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Login" />
    
        </LinearLayout>
    
    </RelativeLayout>
    
    0 讨论(0)
  • 2021-02-09 16:43

    If you want to move whole layout up at the time of soft keyword appears then just add this in your corresponding Activity in manifest file. "android:windowSoftInputMode="adjustResize"

    0 讨论(0)
提交回复
热议问题