On my Home Fragment it contains
ScrollView
LinearLayout
RecycleView
LinearLayout
TabsLayout
ViewPager
TextView (Just to test if the height of ViewPager was updated)
When opening the home screen it will show the Recycle View, Tabs Layout and Text View does not include the View Pager (I did confirm that the adapter was executed properly but the content does not show)
I did try to remove the visibility of the RecycleView and after that
the ViewPager Contents shows up.
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/item_listing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:clipChildren="false"
tools:listitem="#layout/item_categories_content"/>
<include
layout="#layout/fragment_home_news_events"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
fragment_home_news_events.xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/activity_margin"
app:tabSelectedTextColor="#color/colorPrimary"
android:id="#+id/fragment_home_inner_tabs">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/fragment_home_inner_tabs_content">
</androidx.viewpager.widget.ViewPager>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text_label_status"/>
</LinearLayout>
When the RecycleView is visible
When the RecycleView is not visible
You have RecyclerView with include of another layout (fragment_home_news_events) the two had match_parent in height :(
try to fix height to fragment_home_news_events not match_parent.
or
put the height 0dp for both RecyclerView and fragment_home_news_events but with weight 1.
Related
I have a viewpager consisting of 3 fragments. The first two fragments are simply recyclerViews and they scroll upwards perfectly. However in my third fragment, it's a linear layout and it doesn't scroll upwards:
The first two fragment layouts are just recyclers:
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
The third fragment that is not scrolling:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundColor"
android:orientation="vertical">
</LinearLayout>
My viewpager layout:
<?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">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/fragprofile_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:orientation="vertical">
//Collapsing toolbar, etc
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/fragprofile_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Why is this happening?
You should replace the root LinearLayout with ScrollView or NestedScrollView.
Note 1: Android layouts are not scrollable by default.
Note 2: ScrollView and NestedScrollView must have only one direct child (should be a layout of some sort such as a LinearLayout or ConstraintLayout)
Hope this helps.
I have a requirement where I need to code a screen which has a info view in top and view pager with two tabs in the bottom. View pager has two tabs with Recycler View inside it.
The View pager should stick whenever the user scrolls up and then the recycler view inside it should start scrolling. To achieve this I created two separate fragments for top part and bottom part and wrote the xml like this.
<com.citi.mobile.dashboard.views.StickyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/core_color_FFFFFF_white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/title_id"
layout="#layout/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/top_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<FrameLayout
android:id="#+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="sticky">
</FrameLayout>
</LinearLayout>
Inside the the bottom container I have a View Pager.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/TransTabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="#color/core_color_0077bb_blue"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/core_color_0077bb_blue"
app:tabTextAppearance="#style/ledgerTabLayoutTextAppearance"
app:tabTextColor="#color/core_color_666666_grey"
custom:typefaceName="Roboto-Medium" />
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/transaction_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
This has two tabs and each has a recycler view inside this. When I run this the parent scrollview stops working and only the recyclerview scrolling works.
Try adding android:nestedScrollingEnabled="false" to the recyclerview in your xml.
I have a collapsing layout with tab layout and view pager.
Inside the viewpager, in the first tab, I have a NestedScrollView with a lot of children. The problem is: the NestedScrollView is not respecting the children height.
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:isScrollContainer="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
android:background="#color/colorBlack"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="#+id/relative"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:clipToPadding="false">
.... Lots of children
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
The last TextView of this LinearLayout doesn't show. If I put a margin bottom in the TextView of 50dp, it does show.
What I'm missing?
Full code: https://gist.github.com/guuilp/81f06c8a5581d2a9ce0a19dcf6c12ccc
I have a layout similar to the one shown in image below.
Layout Explained
<ScrollView>
<LinearLayout>
...
</LinearLayout>
<ViewPager>
</ScrollView>
ViewPager has a height equal to the height of screen below ActionBar.
While scrolling, when half of the viewPager is visible.. Vertical scroll of RecylerView of fragment in ViewPager interferes with the main scroll of ScrollView.
I want a solution that makes sure the scroll of RecyclerView inside viewpager is disabled untill the viewpager is fully visible.
Main.xml
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/footer"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_marginLeft="#dimen/secondary_margin"
android:layout_marginRight="#dimen/secondary_margin"
android:id="#+id/scroll_view">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/home_deals_slider" />
<include layout="#layout/top_selling_slider" />
...
<TabLayout>
<android.support.v4.view.ViewPager
android:id="#+id/fragments_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/fragments_view_pager_tab" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Fragment.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/staggered_grid_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</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>