Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create Circular Reveal Animation And Ripple Effect

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 571
    Comment on it

     

    In the below example I have created Circular Reveal Animation like chat app(Whatsapp). First I have created activity_main.xml layout, here I have added FrameLayout, all layout and attributes like LinearLayout, ImageButton, TextView, View are added in FrameLayout, after this I have created toolbar.xml layout in that I have created toolbar layout .after this I have added item for attachment icon in menu_main.xml. In MainActivity I have used Animation function, You can see below program it will clearly describe to create Circular Reveal Animation And Ripple Effect.

    Step(1)activity_main.xml-
    
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <include layout="@layout/toolbar" />
    
        <LinearLayout
            android:id="@+id/reveal_items"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="?attr/actionBarSize"
            android:background="#c8e8ff"
            android:orientation="vertical">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:gravity="center"
                android:orientation="horizontal">
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">
    
                    <ImageButton
                        android:id="@+id/linkin"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/one" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:text="LinkedIn" />
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">
    
                    <ImageButton
                        android:id="@+id/google"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/two" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:text="Google" />
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">
    
                    <ImageButton
                        android:id="@+id/twitter"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/three" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:text="twitter" />
                </LinearLayout>
    
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:gravity="center"
                android:orientation="horizontal">
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">
    
                    <ImageButton
                        android:id="@+id/wordpress"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/four" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:text="WordPress" />
    
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">
    
                    <ImageButton
                        android:id="@+id/thumber"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/five" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:text="Thumber" />
    
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">
    
                    <ImageButton
                        android:id="@+id/pocket"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:background="@drawable/six" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="5dp"
                        android:text="Pocket" />
    
                </LinearLayout>
    
            </LinearLayout>
    
            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@android:color/black" />
        </LinearLayout>
    
    </FrameLayout>
    
    
    
    Step(2)-Created toolbar.xml layout-
    
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
    
    Step(3)-Added new item for attachment icon in menu_main.xml -
    
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="com.tiwari.rajshekhar.mywhatsapp.MainActivity">
        <item
            android:id="@+id/action_settings"
            android:orderInCategory="100"
            android:title="@string/action_settings"
            app:showAsAction="never" />
        <item
            android:id="@+id/action_attachment"
            android:icon="@drawable/attach"
            android:title="Media"
            app:showAsAction="ifRoom" />
    </menu>
    
    Step(4)-MainActivity-
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    
    
        Toolbar toolbar;
        boolean hidden=true;
        LinearLayout mRevealView;
        ImageButton ib_linkin,ib_google,ib_twitter;
        ImageButton ib_wordpress,ib_thumber,ib_pocket;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
           toolbar=(Toolbar)findViewById(R.id.toolbar);
            mRevealView=(LinearLayout)findViewById(R.id.reveal_items);
            ib_linkin=(ImageButton)findViewById(R.id.linkin);
            ib_google=(ImageButton)findViewById(R.id.google);
            ib_twitter=(ImageButton)findViewById(R.id.twitter);
            ib_wordpress=(ImageButton)findViewById(R.id.wordpress);
            ib_thumber=(ImageButton)findViewById(R.id.thumber);
            ib_pocket=(ImageButton)findViewById(R.id.pocket);
            ib_linkin.setOnClickListener(this);
            ib_google.setOnClickListener(this);
            ib_twitter.setOnClickListener(this);
            ib_wordpress.setOnClickListener(this);
            ib_thumber.setOnClickListener(this);
            ib_pocket.setOnClickListener(this);
            setSupportActionBar(toolbar);
            mRevealView.setVisibility(View.INVISIBLE);
    
    
        }
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.linkin:
                    Snackbar.make(v,"LinkedIn Clicked",Snackbar.LENGTH_SHORT).show();
                    mRevealView.setVisibility(View.INVISIBLE);
                    hidden=true;
                    break;
                case R.id.google:
                    Snackbar.make(v,"Google Clicked",Snackbar.LENGTH_SHORT).show();
                    mRevealView.setVisibility(View.INVISIBLE);
                    hidden=true;
                    break;
                case R.id.twitter:
                    Snackbar.make(v,"Twitter Clicked",Snackbar.LENGTH_SHORT).show();
                    mRevealView.setVisibility(View.INVISIBLE);
                    hidden=true;
                    break;
                case R.id.thumber:
                    Snackbar.make(v,"Thumber Clicked",Snackbar.LENGTH_SHORT).show();
                    mRevealView.setVisibility(View.INVISIBLE);
                    hidden=true;
                    break;
                case R.id.pocket:
                    Snackbar.make(v,"Pocket Clicked",Snackbar.LENGTH_SHORT).show();
                    mRevealView.setVisibility(View.INVISIBLE);
                    hidden=true;
                    break;
                case R.id.wordpress:
                    Snackbar.make(v,"WordPress Clicked",Snackbar.LENGTH_SHORT).show();
                    mRevealView.setVisibility(View.INVISIBLE);
                    hidden=true;
                    break;
    
    
            }
    
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
    
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
    
            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
           else if(id==R.id.action_attachment){
    
                int cx =(mRevealView.getLeft()+mRevealView.getRight());
                int cy =(mRevealView.getTop());
    
    
                int startradious=0;
                int endradious = Math.max(mRevealView.getWidth(),mRevealView.getHeight());
    
                Animator animator = ViewAnimationUtils.createCircularReveal(mRevealView,cx,cy,startradious,endradious);
                animator.setDuration(400);
    
                int reverse_startradius =Math.max(mRevealView.getWidth(),mRevealView.getHeight());
    
                int reverse_endradius=0;
                Animator animate = ViewAnimationUtils.createCircularReveal(mRevealView,cx,cy,reverse_startradius,reverse_endradius);
                if(hidden){
                    mRevealView.setVisibility(View.VISIBLE);
                    animator.start();
                    hidden=false;
                }
                 else {
                    mRevealView.setVisibility(View.VISIBLE);
                    animate.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            mRevealView.setVisibility(View.INVISIBLE);
                            hidden = true;
                        }
                    });
                    animate.start();
    
                }
                return true;
    
            }
           return super.onOptionsItemSelected(item);
        }
    
    
    }
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: