Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add bottom view to a Coordinator Layout with view pager?

I want to add a bottom view to a Coordinator layout with view pager in it , Bottom View will be on top of fragment loaded by view pager and independent of it .

I added a linear layout with

layout_gravity = "bottom" 

but bottom view linear layout is not showing at all

Following is my xml layout of the activity.

<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.support.design.widget.AppBarLayout     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/maintoolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize"         android:background="?attr/colorPrimary"         app:layout_scrollFlags="scroll|enterAlways"         app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />     <android.support.design.widget.TabLayout         android:id="@+id/maintabs"         android:layout_width="match_parent"         android:layout_height="wrap_content"         app:tabMode="fixed"         app:tabGravity="fill" /> </android.support.design.widget.AppBarLayout>      <android.support.v4.view.ViewPager     android:id="@+id/mainviewpager"     android:layout_width="match_parent"     android:layout_height="match_parent"     app:layout_behavior="@string/appbar_scrolling_view_behavior"  />   <LinearLayout     android:id="@+id/completeBottomView"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="vertical">      <ProgressBar         android:id="@+id/progressBarBottomView"         style="?android:attr/progressBarStyleHorizontal"         android:layout_width="match_parent"         android:layout_height="5dp"         android:indeterminate="false"         android:visibility="gone"         android:max="100"         android:progress="1"/>      <HorizontalScrollView         android:id="@+id/limiter_scroller"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_gravity="bottom|start"         android:background="#FF3399"         >         <LinearLayout             android:id="@+id/limiter_layout"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:orientation="horizontal"             android:onClick="clickFromBottomView"/>     </HorizontalScrollView>  </LinearLayout>  </android.support.design.widget.CoordinatorLayout> 
like image 783
Devansh Kumar Avatar asked Mar 16 '16 21:03

Devansh Kumar


People also ask

How do you set a view at the bottom of a linear layout?

You will have to expand one of your upper views to fill the remaining space by setting android:layout_weight="1" on it. This will push your last view down to the bottom.

Is coordinator layout deprecated?

The previously existing onNestedScroll(CoordinatorLayout, V, View, int, int, int, int, int) has been deprecated in favor of the new onNestedScroll(CoordinatorLayout, V, View, int, int, int, int, int, int[]) and Behavior implementations should be updated accordingly.

What is coordinator layout in Android?

CoordinatorLayout is a super-powered FrameLayout . CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout. As a container for a specific interaction with one or more child views.

How do I use CoordinatorLayout?

Layout-Based: Layout-Based behaviors are used to shift one view to some other place when you perform a certain operation. For example, whenever you click on a Floating Action Button(FAB), then that FAB will be moved up and one Snackbar will come from the bottom of the screen.


2 Answers

As pointed out in comment by @Dhawal ....Solution is to wrap LinearLayout completeBottomView in a FrameLayout with android:layout_gravity="bottom"

like image 163
Devansh Kumar Avatar answered Sep 22 '22 17:09

Devansh Kumar


Android CoordinatorLayout Bottom Layout Behaviour.

activity_bottom.xml

<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.support.design.widget.AppBarLayout         android:id="@+id/app_bar"         android:layout_width="match_parent"         android:layout_height="wrap_content">          <android.support.v7.widget.Toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionBarSize"             android:background="?attr/colorPrimaryDark"             app:layout_scrollFlags="scroll|enterAlways"             app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />     </android.support.design.widget.AppBarLayout>      <android.support.v7.widget.RecyclerView         android:id="@+id/list"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:background="#C0C0C0"         app:layout_behavior="@string/appbar_scrolling_view_behavior" />      <com.example.android.coordinatedeffort.widget.FooterBarLayout         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize"         android:layout_gravity="bottom">          <TextView             android:layout_width="match_parent"             android:layout_height="?attr/actionBarSize"             android:background="#007432"             android:gravity="center"             android:text="Footer View"             android:textColor="@android:color/white"             android:textSize="25sp" />     </com.example.android.coordinatedeffort.widget.FooterBarLayout>  </android.support.design.widget.CoordinatorLayout> 

FooterBarLayout.java

FooterBarBehavior.java

like image 34
Ahamadullah Saikat Avatar answered Sep 19 '22 17:09

Ahamadullah Saikat