I have following activity
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinator">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:id="#+id/catalog_view">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="79dp"
android:background="#color/gray238"
android:id="#+id/top_separator"/>
..
</android.support.constraint.ConstraintLayout>
<include layout="#layout/check_view_sheet"/>
</android.support.design.widget.CoordinatorLayout>
check_view_sheet
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/check_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#color/colorWhite"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="80dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<FrameLayout
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_width="400dp"
android:layout_height="235dp"
android:id="#+id/catalog_view_check_fragment"
/>
<TotalView.TotalView
android:layout_width="match_parent"
android:layout_height="#dimen/totalViewHeight"
android:id="#+id/catalog_total_view" />
</LinearLayout>
View inside framelayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/check_recycler_view"
android:paddingBottom="#dimen/checkBottomPadding"
android:clipToPadding="false"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
The problem is that recycler view is not scrolling.
I tried wrapping framelayout in nestedScrollView, but performance of scroll is horrible - its very laggy and it hides sheet when I try to scroll recycler view down.
How canto fix this ?
Because you are trying do nested scrolling, bottom sheet has scrollable behavior.
try this in RecyclerView
android:nestedScrollingEnabled="true"
if scrolling it in bottom sheet is really mandatory otherwise try by setting it to "false".
Related
This is the layout of my CustomerSearchFragment.
It has a CoordinatorLayout with a AppBarLayout and a ScrollView with a FrameLayout inside.
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.CustomerSearchFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<FrameLayout
android:id="#+id/fl_results_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
The FrameLayout will host CustomerMapResultsFragment, whose layout is shown below:
<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=".fragments.CustomerMapResultsFragment">
<com.mapbox.maps.MapView
android:id="#+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Actual Behaviour: the MapView's heigth is just a bunch of pixels (like 16dp).
Expected behaviour: the MapView has to fill all the available space from the AppBar to the bottom of the screen.
What am I missing? Thanks.
Change your coordinator layout to ConstraintLayout like below code.
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.CustomerSearchFragment">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf=parent
android:layout_height="wrap_content">
...
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="#+id/appbar"
app:layout_constraintBottom_toBottomOf="parent">
<FrameLayout
android:id="#+id/fl_results_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
This will solve your problem.
I solved adding android:fillViewport="true" In the <ScrollView>.
Hi, I have tried to implement the appbar scrolling behavior and it works fine, however, if I scroll when I'm right on the top it seems like there is extra space for one recyclerview row. How do I get rid of the extra space?
activity_main:
<androidx.coordinatorlayout.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=".MainActivity"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|snap|enterAlways" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/nav_host" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
fragment_recyclerview:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.recyclerviewFragment.RecyclerviewFragment"
>
<androidx.recyclerview.widget.RecyclerView
android:paddingTop="?attr/actionBarSize"
android:clipToPadding="false"
android:scrollbars="none"
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_gravity="bottom|right"
app:layout_anchorGravity="bottom|end|right"
app:layout_anchor="#id/recyclerView"
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:backgroundTint="#color/green_300_org"
android:contentDescription="#string/add_a_task"
android:src="#drawable/ic_baseline_add_24"
app:tint="#color/black" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Instead of adding this attribute to the RecyclerView of fragment_recyclerview.xml:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
add it in your activity_main.xml file, and it will work fine.
It will be like:
<include
layout="#layout/nav_host"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
Then you can remove the top padding from your RecyclerView, and you don't need to use CoordinatorLayout in the fragment_recyclerview.xml file as well.
There're two dimentional recyvlerview under nested scroll view under coordinator layout. Clicking to RC items isn't firing with coordinator layout, without it firing good. How to solve it?
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true">
<androidx.core.widget.NestedScrollView
android:id="#+id/main_nsv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#AB9984"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/main_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:scrollbars="none"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".activity.MainActivity">
</androidx.recyclerview.widget.RecyclerView>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I have a recyclerView is positioned inside a SwipeRefreshLayout , the problem is the last element of the recyclerView is always cutoff. here is the Layout code of the fragment.
<?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"
tools:context=".ui.deliveries.DeliveriesFragment">
<ProgressBar
android:id="#+id/DeliveryProgressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/deliveriesList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
I have the below layout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
It's basically having a recyclerView embedded in a SwipeToRefresh. This works well where I could scroll my recyclerView up and down. When reaching the top, and I pull down, the Refresh Happens.
Given I need to add an empty View dynamically, I have wrap the Empty View and RecyclerView under the RelativeLayout. This is as below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="#+id/my_empty_view"
layout="#layout/fragment_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
By adding this RelativeLayout between the RecyclerView and SwipeToRefreshLayout, the RecyclerView can only scroll down. It can not scroll up anymore, as whenever I try to scroll up, the SwipeToRefresh take place instead.
Why is this a problem? Is there any way to solve the problem while retaining my layout?
Thanks!
A scrollable view must be embedded in a SwipeRefreshLayout immediately.So you can let the RelativeLayout be embedded in a ScrollView and the ScrollView is embedded in the SwipeRefreshLayout.
Like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="#+id/my_empty_view"
layout="#layout/fragment_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>