4

I am trying to make an application like UBER and I have completed it to some extant but the problem I am facing is that on main screen when pickUp location animation is shown, an animation is implement that lift whole screen Up and down. I tried a lot to do this but I am not getting any idea. So please can anybody tell me how can I achieve this animation. I am uploading a .gif image for getting the ideaWholeScreenAnimation

Tim
  • 41,901
  • 18
  • 127
  • 145
Junaid
  • 316
  • 5
  • 23

4 Answers4

3

You have to handle scrolls with CoordinatorLayout and use a CollapsingToolbarLayout of Design Support Library.

This two examples may help you :

Collapsing Toolbar Layout

Handling Scrolls with CoordinatorLayout

Farouk Touzi
  • 3,451
  • 2
  • 19
  • 25
1

Set BottomSheetBehaviour class as the layout_behavior of the desired view.
Put the below view inside a layout that has CoordinatorLayout as the root.
Example :

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:keepScreenOn="true"
        android:orientation="vertical"
        android:gravity="center"
        android:id="@+id/bottom_sheet"
        android:clickable="true"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

<!--Add your child views.-->

</LinearLayout>

In your activity, initalise the BottomSheetDialog as :

final View bottomSheet = view.findViewById(R.id.bottom_sheet);
behavior = BottomSheetBehavior.from(bottomSheet); 

To open the BottomSheet, add the following code in the onClickListener of your desired widget.

behaviorProfile.setState(BottomSheetBehavior.STATE_EXPANDED);
AnupamChugh
  • 1,779
  • 1
  • 25
  • 36
0

layout/main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light"
    android:fitsSystemWindows="true"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appbar"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|enterAlways"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="64dp"
            app:expandedTitleMarginEnd="64dp"
            >

            <android.support.v7.widget.Toolbar
                android:id="@+id/main.toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="parallax"
                />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>



    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="72sp"
            android:lineSpacingExtra="8dp"
            android:text="@string/lotsOfText"
            android:padding="@dimen/activity_horizontal_margin"
            />

        <!--PUT VIEWs HERE-->
    </android.support.v4.widget.NestedScrollView>

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

values/styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

1)Import design library in android studio (version may differ) compile 'com.android.support:appcompat-v7:22.1.1'

kishorepatel
  • 139
  • 1
  • 6
0

The layout can be shown like this:

private void showViews() {
    ll_toolBar.animate().translationY(0).setInterpolator(new DecelerateInterpolator (2));
    cardview.animate().translationY(0).setInterpolator(new DecelerateInterpolator (2));
    ll_selectTime.animate().translationY(0).setInterpolator(new AccelerateInterpolator (2));
    fl_carsCategory.animate().translationY(0).setInterpolator(new AccelerateInterpolator(2)).start();
}
Sjoerd222888
  • 3,228
  • 3
  • 31
  • 64
  • private void hideView(){ cardview = (CardView)findViewById (R.id.cardview); ll_toolBar.animate().translationY(-ll_toolBar.getHeight()).setInterpolator(new AccelerateInterpolator(2)); cardview.animate().translationY(-ll_toolBar.getHeight()).setInterpolator(new AccelerateInterpolator(2)); ll_selectTime.animate().translationY(ll_selectTime.getHeight()).setInterpolator(new DecelerateInterpolator(2)); fl_carsCategory.animate().translationY(fl_carsCategory.getHeight()).setInterpolator(new DecelerateInterpolator(2)); } – Asad Naqvi Jun 02 '17 at 08:06
  • You should describe your solution to improve your answer. – Markus Jun 02 '17 at 08:20
  • By using the above code you can show/hide your view with animation on map click like Uber – Asad Naqvi Jun 14 '17 at 13:38