Android - empty space remains after viewing translated

I am trying to animate my toolbar (used as an ActionBar) to hide after scrolling. I use the following code to move the toolbar up -

toolbar.animate().translationYBy(toolbar.getBottom()*(-1)); 

However, after the animation, the space previously occupied by the toolbar becomes white and remains there.

I want the content under the toolbar to move up and occupy the space left by the toolbar.

+6
source share
1 answer

The reason theres a white background after the toolbar animation is due to the way it is embedded in your layout.

There are several ways to achieve this:

  • Make Toolbar Overlay Content

    Use FrameLayout to hold both the toolbar and the contents of your activity.

     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/picture" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/jokic" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/holo_blue_dark" /> </FrameLayout> 

Full screen mode

  1. Save toolbar above content

    As you animate the toolbar, you will also need to animate the layout of the event to take its place. Implementation details will depend on the content you display. For RecyclerView see this blog.

Full screen mode

  1. Hide ActionBar

    Just ask the getSupportActionBar().hide() action getSupportActionBar().hide() hide, and this will redraw the window.

enter image description here

Also, if you want to run full-screen Immersive , this should cover that.

0
source

Source: https://habr.com/ru/post/983282/


All Articles