Make SlidingUpPanelLayout stand above the bottom navbar - android

How to make SlidingUpPanelLayout stand above the bottom navbar? Now my sliding panel standing below navbar because in code of "SlidingUpPanelLayout" sliding layout have to be below of main layout. I have no idea how to do it
how its looks like now
There is my xml file
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nav_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
tools:context=".NavActivity"
app:umanoPanelHeight="70dp"
app:umanoShadowHeight="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:background="#9275B8FA"
android:id="#+id/nav_back" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottom"
android:id="#+id/fragment_container"/>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:id="#+id/bottom"
android:layout_alignParentBottom="true"
android:layout_height="48dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/bottom_navbar"
android:background="#color/blue"
app:itemIconTint="#color/whiteDarker"
app:labelVisibilityMode="unlabeled"
app:itemTextColor="#color/white"
/>
</com.google.android.material.appbar.AppBarLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="#layout/mini_player" />
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

A nice way would be to use a RelativeLayout as parent then set the Panel and Nav Bar as children. Here's a quick example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Notice the attribute layout above -->
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="#+id/nav_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:layout_above="#+id/bottom_navigation"
tools:context=".NavActivity"
app:umanoPanelHeight="70dp"
app:umanoShadowHeight="5dp">
<!-- Fragment container here -->
<!-- Mini Player here -->
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
<!-- Notice the alignParentBottom true -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_navbar"
android:background="#color/blue"
app:itemIconTint="#color/whiteDarker"
app:labelVisibilityMode="unlabeled"
app:itemTextColor="#color/white" />
</RelativeLayout>

Related

floating action button blocks bottom navigation bar

I want my floating action button to be over the listview and above the navigation bar but i cant seem to make it work. (the include layour is the navigation bar).
This is how it looks right now
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SessionsList">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/lvSessions"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="#drawable/ic_baseline_add_24"
android:contentDescription=""
android:layout_margin="16dp" />
<include layout="#layout/activity_base"/>
</FrameLayout>
</LinearLayout>
This is the navigation bar layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BaseActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="60dp"
app:itemBackground="#color/orange"
app:itemIconTint="#drawable/selector"
app:itemTextColor="#drawable/selector"
android:layout_gravity="bottom"
app:menu="#menu/menu_navigation" />
</LinearLayout>
I tried putting it in a frame layout and moving things around but I cant get it to work like I want it to.
Change your main layout like this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/lvSessions"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="#+id/baseLayout"
layout="#layout/activity_base"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_above="#+id/baseLayout"
android:layout_alignParentEnd="true"
android:src="#drawable/g1" />
</RelativeLayout>
</FrameLayout>
And also change activity_base layout like this
<LinearLayout 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">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
app:itemBackground="#color/black" />
</LinearLayout>

Disable scrolling of a button in a scrollable layout in android

I have a coordinator layout with a FrameLayout in it.
I set app:layout_behavior="#string/appbar_scrolling_view_behavior" for this framelayout.
but i want to have a button in this fragment that is fixed and i don't want that this button have scroll .
how should i do this??
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:fitsSystemWindows="true"
tools:openDrawer="end">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- AppBarLayout is a wrapper for a Toolbar in order to apply scrolling effects. -->
<!-- Note that AppBarLayout expects to be the first child nested within a CoordinatorLayout -->
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:elevation="0dp">
<!-- Toolbar is the actual app bar with text and the action items -->
<include
android:id="#+id/action_bar"
layout="#layout/custom_action_bar" />
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/but_nav_bar"
android:layout_marginTop="-25dp"
android:layout_marginBottom="#dimen/_30sdp"
android:paddingBottom="#dimen/_30sdp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<include layout="#layout/bottom_navigation_layout" />
<include layout="#layout/navigation_bar" />
</androidx.drawerlayout.widget.DrawerLayout>
and this is code of myFragment
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/shopsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="40dp"
text="button"/>
</RelativeLayout>
You have not mentioned where you want a button to be fixed.
Adding android:layout_alignParentBottom="true" will fixed the button at the bottom of the screen.
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:text="button" />

How to keep bottom navigation stay at the bottom by using Scrollview with the child is LinearLayout as the root

How to make my bottom navigation stay at the bottom with the root parent being Scrollview? The bottom navigation did not stay at the bottom when I change my root parent which is Scrollview.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fillViewport="true"
tools:context=".ManageActivity">
<LinearLayout ... >
<androidx.cardview.widget.CardView ...>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/btm_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/purple"
android:clipToPadding="false"
app:itemIconTint="#color/bottom_nav_color"
app:itemTextColor="#color/bottom_nav_color"
app:menu="#menu/bottom_nav" />
</LinearLayout>
</ScrollView>
Try like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/navigation" >
<!--Other Stuff here-->
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/purple"
android:clipToPadding="false"
app:itemIconTint="#color/bottom_nav_color"
app:itemTextColor="#color/bottom_nav_color"
app:menu="#menu/bottom_nav" />
</RelativeLayout>

Android RecyclerView Gravity issue

I am using DrawerLayout to show Navigation Drawer, in that A NavigationView, the xml code is :
MyDrawerLayout.xml
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<include layout="#layout/layout_navigation_list" />
</android.support.design.widget.NavigationView>
layout_navigation_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<include
android:id="#+id/headerLayout"
layout="#layout/nav_header_dash_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:gravity="top" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#color/white"
android:foregroundGravity="bottom" />
</RelativeLayout>
In the RecyclerView i have only 3 items to be shown, and they are aligning on the top of the RecyclerView layout which is i don't want. Hence my question here is , how to send those items to the bottom of the RecyclerView (just like shown in the image).
Set match_parent instead wrap_content field layout_height in relativeLayout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
Insert a ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/white"
android:orientation="vertical">
<include
android:id="#+id/headerLayout"
layout="#layout/nav_header_dash_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="top"
android:gravity="top" />
<android.support.constraint.ConstraintLayout
android:layout_below="#id/headerLayout"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
You should have to MATCH_PARENT height instead of WRAP_CONTENT in root relative layout in file layout_navigation_list.xml. So it looks like,
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
...
...
...
</RelativeLayout>
Notes: Gravity won't work with relative layouts.

Android Coordinator Layout bottom bar hide inside the list view

The bottom button/some view hides the list view bottom part.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="example.design.activities.DetailsActivity"
android:background="#color/grey">
<android.support.v7.widget.RecyclerView
android:paddingTop="80dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom">
<!-- Add to cart button -->
<android.support.v7.widget.AppCompatButton
android:id="#+id/ssssss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="ADD TO CART"
android:backgroundTint="#color/colorPrimary"
android:textColor="#color/white"
android:layout_alignParentBottom="true"
android:visibility="visible" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
I will make the bottom view visible and invisible based on condition.
How can I adjust my list view to scroll more if the bottom bar is visible ?
I think this will solve your problem,
<?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.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true"
android:background="#android:color/darker_gray">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="match_parent"
android:layout_above="#+id/ssssss"/>
<!-- Add to cart button -->
<android.support.v7.widget.AppCompatButton
android:id="#+id/ssssss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="ADD TO CART"
android:layout_alignParentBottom="true"
android:backgroundTint="#color/colorPrimary"
android:textColor="#android:color/white"
android:visibility="visible" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
here is the sample output
NOTE:
you have added android:fitsSystemWindows="true" and so you need android:paddingTop="80dp" in your recycler view.Instead you can follow as in my solution just give android:fillViewport="true" to nestedScrollView and no padding needed for recyclerview.
I hope this solves your issue
You can add android:clipToPadding = "false" in your NestedScrollView.
And when you are showing your bottom button you can dynamically add bottom padding for NestedScrollview with value equals to height of your bottom button.
nestedScrollView.setPadding(yourPadding, yourPadding,yourPadding, btn.getMeasuredHeight())
You should change NestedScrollView by using layout_anchor as below.
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="example.design.activities.DetailsActivity"
android:background="#color/colorPrimary"
app:layout_anchor="#+id/relative_view"
app:layout_anchorGravity="top">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:paddingTop="80dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
It put scrollview on top of your bottom bar as per your aspect.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EAEAEA"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="example.design.activities.DetailsActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Add to cart button -->
<android.support.v7.widget.AppCompatButton
android:id="#+id/ssssss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:backgroundTint="#color/colorPrimary"
android:padding="20dp"
android:text="ADD TO CART"
android:textColor="#FFFFFF"
android:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/ssssss"
android:layout_alignParentTop="true"
android:paddingTop="80dp" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Categories

Resources