The sticker at the bottom of the viewport fragment inside the coordinator

I have a viewpager that fits inside the coordinator layout. In a specific viewpager fragment, I have a recycler view and a bottom view of the fragment. The problem is that initially the bottom view of the fragment is hidden and is displayed only when I look up. I want the view to remain at the bottom of the screen.

File Name: activity_main.xml

<android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" style="@style/ToolBarStyle" android:layout_width="match_parent" android:layout_height="?actionBarSize" android:layout_alignParentTop="true" android:background="@color/toolbarColor" android:contentInsetEnd="16dp" android:contentInsetRight="16dp" android:minHeight="?actionBarSize" android:paddingBottom="0dp" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="com.dekorate.android.Utils.AppBarLayoutBehavior" /> </android.support.design.widget.CoordinatorLayout> 
+7
android android-layout androiddesignsupport
source share
1 answer

Deploy AppBarLayout.OnOffsetChangedListener to the action. In the onOffsetChanged method, adjust the edge of the view below to match the current scroll.

 @Override public void onOffsetChanged(AppBarLayout appBarLayout, int i) { RelativeLayout.LayoutParams bottomLayoutParams = (RelativeLayout.LayoutParams)fragment.bottomLayout.getLayoutParams(); bottomLayoutParams.setMargins(0,0,0,(actionBarHeight + i)); fragment.bottomLayout.setLayoutParams(bottomLayoutParams); } 

Here, the fragment is an instance of your fragment, and bottomLayout is the view below.

0
source share

All Articles