Android Toolbar isn't showing up - android

I use drawer, bottom navigation bar and toolbar in my app.
So I put my toolbar by including layout in drawer layout .
Drawer works well by swiping, but Toolbar isn't showing up.
I think toolbar is covered by fragment,but I don't know why...
I already setSupportActionBar in MainActivity.
What's the problem??
toolbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#android:color/transparent"
android:id="#+id/toolbar"
>
<Button
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/ic_menu"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<Button
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/ic_search"
android:layout_marginEnd="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.appcompat.widget.Toolbar>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
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:id="#+id/drawer"
android:fitsSystemWindows="true"
>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<include
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/toolbar_layout"
/>
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/navigationView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/gray7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:itemBackground="#color/gray7"
app:labelVisibilityMode="labeled"
android:theme="#style/Widget.BottomNavigationView"
app:itemIconTint="#drawable/menu_selector_color"
app:itemTextColor="#drawable/menu_selector_color"
app:menu="#menu/bottom_navigationbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nvDrawer"
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="start"
>
<include layout="#layout/drawer_layout"/>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>

You are setting your FrameLayout containter from the top of the parent view
change this
app:layout_constraintTop_toTopOf="parent"
with
app:layout_constraintTop_toBottomOf="#+id/toolbar"

Related

how to hide bottomnavigation and app bar on scroll when app bar inside FragmentContainerView

I know we can hide bottomnavigation and app bar on scroll when both are the direct children of coordinate layout, But my issue is different, I have one home fragment and bottom view is a part of this fragment with FragmentContainerView, now my app bar inside the fragment which i am setting in container view, when i am scrolling, app bar getting scroll properly but i am not sure how to scroll bottom navigation as well,
home_fragment:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/rootFragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemIconTint="#drawable/nav_bar_tab_color"
android:background="?android:attr/windowBackground"
app:itemTextAppearanceActive="#style/navText"
app:itemTextAppearanceInactive="#style/navText"
app:itemTextColor="#drawable/nav_bar_tab_color"
app:labelVisibilityMode="unlabeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/navigation_items" />
</androidx.constraintlayout.widget.ConstraintLayout>
another fragment:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:fitsSystemWindows="true">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/appbar"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvLay"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/rvProgressBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="#+id/rvProgressBar"
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#color/colorWhite"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat" >
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/twentyfour_24dp"
android:paddingBottom="#dimen/eighteen_18dp"
android:text="#string/t2"
android:gravity="center"
android:textAllCaps="true"
style="#style/text_16px_franklin_gothic_normal_" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Can some one please explain me, how to achieve it?
Have you tried to add app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior" inside your BottomNavigationView? In my case, it works just fine :)
I also suggest you to use CoordinatorLayout instead of ConstraintLayout in your home_fragment.xml

BottomNavigationView and AppBar covers fragment with recyclerview

I have an issue with placing fragment and making it scroll without being overlapped by bottomNavigationView and AppBar. So my content is covered by BottomNavigationView and AppBar.How i can make my content visible when I am scrolling page or appBar and BottomNavigationView invisible while scrolling page down?
my activity_main.xml:
<?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"
android:id="#+id/drawerLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="#+id/mainToolbar"
style="#style/mainToolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:elevation="0dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="8dp"
app:layout_constraintBottom_toTopOf="#id/bottomNavigationView"
android:background="#drawable/shadow"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_menu"/>
<fragment
android:layout_marginTop="130dp"
android:id="#+id/dataContainer"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="409dp"
android:layout_height="673dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/mainToolbar"
app:navGraph="#navigation/my_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:headerLayout="#layout/nav_header"
app:menu="#menu/nav_drawer_menu"
android:layout_gravity="start"
android:fitsSystemWindows="true" />
</androidx.drawerlayout.widget.DrawerLayout>
Is there any solutions?
Make the height of your fragment tag that hold nav host fragment 0dp
In your activity_main.xml
<fragment
android:layout_marginTop="130dp"
android:id="#+id/dataContainer"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="409dp"
android:layout_height="673dp" ---------> ( make it 0dp )
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/mainToolbar"
app:navGraph="#navigation/my_nav" />

android - Implement DrawerLayout with BottomNavigationView and FrameLayout

Im currently creating an app, which has a BottomNavigationView and a FrameLayout for fragments. I would like to implement a DrawerLayout or Hamburger Menu too, however, as said in this video
A DrawerLayout should only contain two views, one for the ActivityFragment and one for the NavigationView
Is it possible then to implement the DrawerLayout while having the BottomNavigationView? If yes, how?
This is my activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
<FrameLayout
android:id="#+id/framelayoutFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="56dp"
app:backgroundTint="#color/colorSecondaryDark"
app:elevation="0dp"
app:itemIconTint="#drawable/selector"
app:itemTextColor="#drawable/selector"
app:labelVisibilityMode="selected"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/menu_bottomnavgation" />
</androidx.constraintlayout.widget.ConstraintLayout>
Yes, you can implement the DrawerLayout while having the BottomNavigationView, try 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:openDrawer="start"
android:id="#+id/drawer_layout">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tool_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/btm_nav"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tool_bar" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/btm_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/nav"
android:background="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/nav_dr"
app:menu="#menu/nav"
android:layout_gravity="start"/>
</androidx.drawerlayout.widget.DrawerLayout>

BottomNavigationView is visible even if view is top of it

I have screen with 3 main parts
toolbar
homeContaner(will host fragments of BottomNavigationView)
mainContainer (host splash screen or any screen that take full of screen)
when replace mainContainer with splash BottomNavigationView is also shown
I tried to add background color to mainContainer and found that BottomNavigationView is on Top of mainContainer
also tried to add elevation to mainContainer but got no new results
Screen shots
full code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".feature.home_Activity.HomeActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:titleTextColor="#android:color/white"/>
<FrameLayout
android:id="#+id/homeContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="#id/dummy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/toolbar" />
<View
android:id="#+id/dummy"
android:layout_width="match_parent"
android:layout_height="#dimen/_10sdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/navigation" />
<FrameLayout
android:id="#+id/mainContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:elevation="10dp"
android:background="#ffaaff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Wrap BottomNavigationView with LinearLayout solved the problem
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".feature.home_Activity.HomeActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="#android:color/white" />
<FrameLayout
android:id="#+id/homeContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="#id/dummy"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/toolbar" />
<View
android:id="#+id/dummy"
android:layout_width="match_parent"
android:layout_height="#dimen/_10sdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/navigationContainer" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/navigationContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bn_bg"
app:elevation="1dp"
app:itemBackground="#drawable/bn_item__bg"
app:itemIconTint="#color/secondaryTextColor"
app:itemTextColor="#color/primaryTextColor"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/navigation" />
</androidx.appcompat.widget.LinearLayoutCompat>
<FrameLayout
android:id="#+id/mainContainer"
android:layout_width="0dp"
android:layout_height="0dp"
app:elevation="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

FloatingActionBar hidden under bottom navigation bar

My fragment layout contains a CoordinatorLayout with a FloatingActionButton. The parent activity also contains a CoordinatorLayout with a PageView that brings in the fragment. The problem I have is that the FAB sits under the navigation bar instead of above it. It also moves up and down as I scroll the associated RecyclerView, whereas I want it to remain fixed. Here's the XML layout code for the activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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"
tools:context="uk.ac.aber.dcs.cs31620.faaversion4.ui.FAAMainActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_main" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:itemTextColor="?android:textColorPrimary"
app:itemIconTint="?colorPrimaryDark"
app:menu="#menu/menu_nav" />
</android.support.v4.widget.DrawerLayout>
Here's the code for the toolbar:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:layout_scrollFlags="scroll|enterAlways"/>
Finally, here's the code for the fragment layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="uk.ac.aber.dcs.cs31620.faaversion4.ui.cats.CatsFragment">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridLayout
android:id="#+id/gridLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:columnCount="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Spinner
android:id="#+id/breeds_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="50"
android:layout_row="0" />
<Spinner
android:id="#+id/gender_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="50"
android:layout_row="0" />
<Spinner
android:id="#+id/age_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="50"
android:layout_row="1" />
<TextView
android:id="#+id/proximity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="50"
android:layout_row="1"
android:text="#string/distance"
android:textAppearance="#style/MyTextAppearance" />
</GridLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/cat_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/gridLayout" />
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add_cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:src="#drawable/ic_add_white_24dp"
android:layout_gravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
As a workround I put a layout_MarginBottom on the FAB of 64dp but although it displayed it still moved up and down as the tab bar collapsed. Also, a generated Snackbar was also hidden under the bottom navigation bar. All the examples I've seen have the FAB and coordinator layout at the activity level, and without nesting of a further coordinator layout. Perhaps the only option is to put the FAB in the activity layout and access it from the fragments (e.g. hid it when not needed)? Thanks.
If you are going to use a ConstraintLayout you should think about harnessing the power of it so that your UIs act accordingly. ConstraintLayouts help you remove the nesting of widgets and layouts. It makes them flatter, more readable, reducing code and making your app smoother.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="uk.ac.aber.dcs.cs31620.faaversion4.ui.FAAMainActivity">
<Spinner
android:id="#+id/breeds_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="#id/gender_spinner"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="#+id/gender_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/breeds_spinner"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="#+id/age_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="#id/gender_spinner"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/breeds_spinner" />
<TextView
android:id="#+id/proximity_button"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="#string/distance"
android:textAppearance="#style/MyTextAppearance"
app:layout_constraintBottom_toBottomOf="#id/age_spinner"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/age_spinner"
app:layout_constraintTop_toBottomOf="#id/gender_spinner" />
<android.support.v7.widget.RecyclerView
android:id="#+id/cat_list"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/age_spinner" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add_cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:src="#drawable/ic_add_white_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>

Categories

Resources