I made a quick dummy application similar to yours and tried to achieve what you showed in your animation. Check out the effect below (you can make it smoother and more elegant):

Its a bit tricky way to do how I did it. Here I post all my code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pabhinav.testapp3"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
<h / "> MainActivity.java
package com.pabhinav.testapp3; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.LinearInterpolator; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import static com.pabhinav.testapp3.R.id.container; public class MainActivity extends AppCompatActivity implements PlaceholderFragment.OnSearchBoxClick{ private SectionsPagerAdapter mSectionsPagerAdapter; private ViewPager mViewPager; private RelativeLayout dummySearchBox; private LinearLayout topSearchBox; private View overlay; private ImageView backButtonSearchBox; private PlaceholderFragment placeholderFragment; private float xDelta, yDelta; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
PlaceholderFragment.java
package com.pabhinav.testapp3; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; public class PlaceholderFragment extends Fragment { private LinearLayout searchLayout; public PlaceholderFragment() { } private OnSearchBoxClick onSearchBoxClick; public void setOnSearchBoxClick(OnSearchBoxClick onSearchBoxClick){ this.onSearchBoxClick = onSearchBoxClick; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int sectionNumber = getArguments().getInt(MainActivity.SectionsPagerAdapter.ARG_SECTION_NUMBER); View rootView = inflater.inflate((sectionNumber == 2) ? R.layout.fragment_search : R.layout.fragment_main, container, false); if(sectionNumber != 2) { TextView textView = (TextView) rootView.findViewById(R.id.section_label); textView.setText(getString(R.string.section_format, sectionNumber)); } else {
<h / "> activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="com.pabhinav.testapp3.MainActivity"> <android.support.design.widget.TabLayout android:layout_marginTop="8dp" android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="56dp" android:id="@+id/top_search_box" android:visibility="invisible" android:orientation="horizontal"> <RelativeLayout android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white"> <ImageView android:gravity = "center" android:layout_width="52dp" android:paddingLeft="24dp" android:paddingRight="8dp" android:id="@+id/search_icon" android:layout_height="match_parent" android:src="@drawable/ic_arrow_back_black_24dp"/> <EditText android:layout_toEndOf="@+id/search_icon" android:hint="@string/search_soundcloud" android:textSize="18sp" android:background="@android:color/transparent" android:textColorHint="#B3B3B3" android:layout_margin="4dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> </LinearLayout> <RelativeLayout android:id="@+id/dummy_search_box" android:layout_width="match_parent" android:layout_below="@+id/tabs" android:visibility="invisible" android:layout_height="wrap_content" android:padding="16dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="56dp" android:id="@+id/search_linear_layout_dummy" android:orientation="horizontal"> <RelativeLayout android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:background="@android:color/white" android:elevation="2dp" android:translationZ="2dp"> <ImageView android:gravity = "center" android:layout_width="20dp" android:layout_marginStart="16dp" android:id="@+id/search_icon_dummy" android:layout_height="match_parent" android:src="@drawable/ic_search_light_black_24dp"/> <EditText android:id="@+id/search_edit_text" android:layout_toEndOf="@+id/search_icon_dummy" android:hint="@string/search_soundcloud" android:textSize="16sp" android:background="@android:color/transparent" android:textColorHint="#B3B3B3" android:layout_margin="4dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> </LinearLayout> </RelativeLayout> <android.support.v4.view.ViewPager android:layout_below="@+id/tabs" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" /> <View android:id="@+id/overlay_whole_page" android:layout_below="@+id/tabs" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:background="#72000000" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@+id/tabs" android:background="#42000000" /> </RelativeLayout>
fragment_search.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="com.pabhinav.testapp3.MainActivity$PlaceholderFragment"> <LinearLayout android:layout_width="match_parent" android:layout_height="56dp" android:id="@+id/search_linear_layout" android:orientation="horizontal"> <RelativeLayout android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:background="@android:color/white" android:elevation="2dp" android:translationZ="2dp"> <ImageView android:gravity = "center" android:layout_width="20dp" android:layout_marginStart="16dp" android:id="@+id/search_icon" android:layout_height="match_parent" android:src="@drawable/ic_search_light_black_24dp"/> <TextView android:id="@+id/search_text" android:layout_toEndOf="@+id/search_icon" android:text="@string/search_soundcloud" android:gravity="center_vertical" android:textColor="#B3B3B3" android:textSize="16sp" android:layout_margin="4dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> </LinearLayout> <TextView android:id="@+id/suggested_stations" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="56dp" android:textSize="18sp" android:layout_below="@+id/search_linear_layout" android:text = "@string/suggested_stations"/> <LinearLayout android:layout_below="@+id/suggested_stations" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="0dp" android:layout_height="240dp" android:src="@drawable/image_1" android:layout_weight="1"/> <ImageView android:layout_marginStart="16dp" android:layout_width="0dp" android:layout_height="240dp" android:src="@drawable/image_2" android:layout_weight="1"/> </LinearLayout> </RelativeLayout>
<h / "> Download the entire project from here: https://drive.google.com/file/d/0B_Mi44NWLWmyNFNkeHJ6cVBLTTg/view?usp=sharing
Hope this helps!
source share