I have the following activity layout:
<?xml version="1.0" encoding="utf-8"?>
<layout
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">
<data>
<import type="com.aurelhubert.ahbottomnavigation.AHBottomNavigation" />
<variable
name="viewModel"
type="[...]android.ui.MainViewModel" />
</data>
<RelativeLayout
android:id="#+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottom_navigation" />
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="#dimen/bottom_navigation_height"
android:layout_alignParentBottom="true"
app:accentColor="#color/bottomNavActive"
app:defaultBackgroundColor="#{#color/bottomNavBg}"
app:inactiveColor="#color/bottomNavInactive"
app:titleState="#{AHBottomNavigation.TitleState.ALWAYS_SHOW}"
app:useElevation="#{false}" />
<FrameLayout
android:id="#+id/floating_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</RelativeLayout>
</layout>
And a fragment that is displayed in FrameLayout:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="viewModel"
type="[...]android.ui.home.jobs.JobsViewModel" />
<variable
name="navigationViewModel"
type="[...]android.ui.NavigationViewModel" />
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/extended_toolbar_height"
android:theme="#style/AppBarLayoutTheme">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginBottom="#dimen/extended_toolbar_title_margin_bottom"
app:expandedTitleMarginEnd="#dimen/content_indent_end"
app:expandedTitleMarginStart="#dimen/content_indent_start"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="#string/jobs_title" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:itemBinding="#{viewModel.itemBinding}"
app:items="#{viewModel.items}"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
The whole fragment should be displayed above the AHBottomNavigation as folows:
Desired state
However, sometimes when switching tabs or rotating screen the result is as folows (content is overlapped by the bottom navigation; cannot scroll more):
Bottom menu overlapping the content
It seems that the root of the issue is somehow in the CollapsingToolbarLayout, not the AHBottomNavigation (does not work even if AHBottomNavigation is replaced by something else).
Do you have any idea where could be the problem? Thanks for any suggestions.
Related
I have a fragment called PostsFragment which is used on two places.
HomeActivity
PostActivity
In the HomeActivity, I am attaching PostsFragment and everything is going well, but, In the second activity PostActivity, I have in the top some components -post details- and below them, there is FragmentContainerView where I want to attach it again, -I want to display the related posts-.
The PostActivity parent's view is NestedScrollView.
when I set nestedScrollingEnabled to true inside PostsFragment the scrollbar only works on the recyclerView but I want to make the whole view in PostActivity scrollable, which doesn't work if I set nestedScrollingEnabled to false.
I did lots of searches and nothing works.
Edit 1:
Here is the code of PostActivity
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<import type="android.view.View" />
<variable
name="viewModel"
type="com.trade.scope.ui.project.ProjectViewModel" />
</data>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.project.ProjectActivity">
<com.trade.scope.ui.custom.ViewPagerPauseAble
android:id="#+id/image_view_banner"
android:layout_width="match_parent"
android:layout_height="256dp"
android:layout_marginHorizontal="16dp"
app:layout_collapseMode="parallax"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/text_view_title_"
style="#style/Auth.Sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="18dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="18dp"
android:fontFamily="#font/muller_bold"
android:text="#string/project_request"
android:textColor="#color/dark_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image_view_banner" />
<FrameLayout
android:id="#+id/divider"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginTop="8dp"
android:background="#drawable/primary_line"
app:layout_constraintStart_toStartOf="#+id/text_view_title_"
app:layout_constraintTop_toBottomOf="#+id/text_view_title_"
app:layout_constraintWidth_percent="0.4" />
<androidx.fragment.app.FragmentContainerView
android:id="#+id/fragment_container_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
app:layout_constraintTop_toBottomOf="#+id/divider" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</layout>
The code of PostsFragment
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="viewModel"
type="com.trade.scope.ui.projects.ProjectsViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:orientation="vertical"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="#layout/view_holder_project" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
You're building a complex view, I can recommend CoordinatorLayout with AppBarLayout and CollapsingToolbarLayout and don't miss the app:layout_behavior="#string/appbar_scrolling_view_behavior"
You have 2 options:
Put nestedScrollingEnabled programally like this:
yourRecyclerView.isNestedScrollingEnabled = false
Put into your recyclerview in xml file
android:nestedScrollingEnabled="false"
Hope it's help you
You have not posted your code so I am assuming this might be the case. You have to set the nestedScrollingEnabled to false for recyclerview not for NestedScrollView
I have a main activity which has the navigation drawer and a FrameLayout to add fragments dynamically. The layout of one of the fragments has a RecyclerView and I want the RecyclerView to take the entire height of the device so that the RecyclerView scrolls beneath the ToolBar and bottom navigation. I am adding fast scroll to the RecyclerView but the verticalscrolldrawable is also scrolling between the entire height of the device but I want that to restrict between bottom nav and ToolBar like in google photos.
Sample Image - https://i.stack.imgur.com/55sh7.jpg
activity_main
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<import type="android.view.View" />
<import type="com.nowfloats.laxmi.home.ui.HomeActivity" />
<variable
name="home"
type="HomeActivity" />
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".home.ui.HomeActivity">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/extended_fab"
style="#style/Widget.MaterialComponents.ExtendedFloatingActionButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/dp_16"
android:backgroundTint="#color/laxmi_green"
android:text="#string/add_new_inventory"
android:textColor="#color/white"
android:textSize="#dimen/sp_12"
android:visibility="#{home.fabObservable ? View.VISIBLE : View.GONE}"
app:fabSize="mini"
app:icon="#drawable/ic_add"
app:iconPadding="#dimen/dp_4"
app:iconSize="#dimen/dp_20"
app:iconTint="#color/white"
app:layout_anchor="#id/bottom_navigation"
app:layout_anchorGravity="top|right"
app:layout_insetEdge="bottom" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="#dimen/navigation_drawer_height"
android:layout_gravity="bottom"
android:alpha=".98"
android:background="#color/laxmi_light_green"
android:theme="#style/Widget.BottomNavigationView"
app:itemIconTint="#drawable/bottom_navigation_drawable_colors"
app:itemTextAppearanceActive="#style/BottomNavigationView.Active"
app:itemTextAppearanceInactive="#style/BottomNavigationView"
app:itemTextColor="#drawable/bottom_navigation_drawable_colors"
app:labelVisibilityMode="labeled"
app:menu="#menu/bottom_navigation_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
product_fragment-
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:clipChildren="false">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:fastScrollEnabled="true"
android:paddingBottom="#dimen/navigation_drawer_height"
app:fastScrollHorizontalThumbDrawable="#drawable/thumb_drawable"
app:fastScrollHorizontalTrackDrawable="#drawable/line_drawable"
app:fastScrollVerticalThumbDrawable="#drawable/thumb_drawable"
app:fastScrollVerticalTrackDrawable="#drawable/line_drawable"
tools:listitem="#layout/product_list_single_item" />
<androidx.appcompat.widget.Toolbar
android:id="#+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:background="#color/white"
tools:context=".products.ui.ProductFragment">
</androidx.appcompat.widget.Toolbar>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I have a custom action toolbar and I'm using data binding. In toolbar is edittext and button. How in my case bind that edittext with viewmodel and pass the value there?
My toolbar in xml is separated. Of course I'have pasted this in activity, but I also have the two fragments and I need working toolbar in these two fragments so this is a reason why I separated that.
toolbar:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/design_default_color_primary_dark"
android:theme="#style/Base.ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/city_edit_text"
android:layout_width="200dp"
android:layout_height="40dp"
android:textColor="#color/colorWhite"
android:hint="Search location"
android:textColorHint="#color/colorGrey"
android:background="#android:color/transparent"/>
</androidx.appcompat.widget.Toolbar>
menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/search_bar"
android:title="Search"
android:icon="#drawable/ic_search_white_24dp"
app:showAsAction="always"/>
main_activity:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="mainViewModel"
type="com.example.daniellachacz.weatherapp2.viewmodel.MainViewModel">
</variable>
<variable
name="todayFragmentInterface"
type="com.example.daniellachacz.weatherapp2.view.TodayFragmentInterface"
/>
</data>
<RelativeLayout
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=".view.MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
/>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_navigation"
android:layout_marginTop="55dp">
</FrameLayout>
<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_navigation"
android:background="#color/design_default_color_primary_dark"
app:itemIconTint="#color/colorWhite"
app:itemTextColor="#color/colorWhite">
</com.google.android.material.bottomnavigation.BottomNavigationView>
while integrating the BottomSheet we need to make the parent layout as the CoordinatorLayout but in databinding we use <layout>. While implementing this it throws an exception :-
Caused by: java.lang.IllegalArgumentException: The view is not a child of CoordinatorLayout.
How to integrate BottomSheet with databinding
<layout>
<data>
<import type="android.view.View" />
<variable
name="cabLayoutBinder"
type="newage.com.hopin.rideBooking.CabSelectActivity" />
<variable
name="modelBinder"
type="newage.com.hopin.rideBooking.model.DataBinders" />
<variable
name="fareSetters"
type="newage.com.hopin.rideBooking.model.FareDetails" />
</data>
<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"
tools:context=".rideBooking.CabSelectActivity">
</android.support.design.widget.CoordinatorLayout>
</layout>
You put context in your coordinator, but in databinding you don't implement this way.
Try to remove this line and try again:
tools:context=".rideBooking.CabSelectActivity"
Let me know if it worked.
This is how I am using it
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".com.abc.Activity">
<data>
<variable
name="viewModel"
type=".com.abc.ViewModel" />
</data>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
layout="#layout/toolbar" />
</FrameLayout>
<!-- Adding bottom sheet after main content -->
<include layout="#layout/bottom_sheet" />
</android.support.design.widget.CoordinatorLayout>
</layout>
I am trying to show toolbar along with the menu items in an activity. This works fine until I add databinding to the xml. I can not use setSupportActionBar(toolbar) at all after that. Here is my xml file activity_single_product.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable name="product"
type="com.sales.models.ProductModel"/>
<variable name="glide" type="com.bumptech.glide.Glide" />
</data>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_view_single_product"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.sales.SingleProductActivity"
android:background="#color/colorPrimary">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/tool"
layout="#layout/toolbar" />
<include
android:id="#+id/search_layout"
layout="#layout/search_layout" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#drawable/drop_shadow_toolbar" />
</LinearLayout> <!-- Toolbar & Search bar-->
</RelativeLayout>
</layout>
The Activity :
private void initViews() {
binding = DataBindingUtil.setContentView(this, R.layout.activity_single_product); // ActivitySingleProductBinding
setSupportActionBar(binding.tool.toolbar);
binding.setProduct(product);
}
I have followed stackoverflow answer. This didn't help. Can anyone suggest?
I have found and fixed the problem. The problem was in toolbar layout. I included
<include
android:id="#+id/tool"
layout="#layout/toolbar" />
and the toolbar layout was
<android.support.v7.widget.Toolbar
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:layout_marginTop="25dp"
android:background="#null"
android:titleTextColor="#color/lightGrey2"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:contentInsetLeft="10dp"
android:contentInsetRight="10dp"
android:contentInsetStart="10dp"
android:padding="0dp"
app:contentInsetLeft="10dp"
app:contentInsetRight="10dp"
app:contentInsetStart="10dp"/>
The problem was , I did not include proper tag to wrap the toolbar. Later I changed it and the new toolbar layout is
<layout
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:layout_marginTop="25dp"
android:background="#null"
android:titleTextColor="#color/lightGrey2"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:contentInsetLeft="10dp"
android:contentInsetRight="10dp"
android:contentInsetStart="10dp"
android:padding="0dp"
app:contentInsetLeft="10dp"
app:contentInsetRight="10dp"
app:contentInsetStart="10dp"/></layout>
This solved the issue.