scroll views and RecyclerView at same time - android

want to scroll RecyclerView and views in scroll view, in this code scroll only work on views but not scroll the RecyclerView or scroll hide the RecyclerView.I am using nested scrollview but same not working.
scroll views and RecyclerView like as one layout is scrolling.
<?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">
<ScrollView
android:id="#+id/scrol"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/topRl5"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/nested_scrol"
android:orientation="vertical"
android:visibility="visible">
<com.github.mikephil.charting.charts.BarChart
android:id="#+id/chart1"
android:layout_width="match_parent"
android:layout_height="#dimen/_300sdp"
android:layout_below="#+id/weekly_summary"
android:visibility="visible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/grey_light"
android:gravity="center"
android:padding="#dimen/_5sdp"
android:text="تفصیلی رپورٹ"
android:textSize="#dimen/_15sdp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/daily_earning_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/scrol"
android:visibility="visible">
<include
layout="#layout/weekly_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
Here is my RecyclerView i include it in main class
<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:layout_width="match_parent"
android:layout_height="wrap_content"
tools:showIn="#layout/activity_barchart"
tools:context=".guaranteeDetails.baarChart.BarChartActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/weekly_recycler_view"
android:layout_marginRight="#dimen/_4sdp"
android:layout_marginLeft="#dimen/_4sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

Use should use NestedScrollView instead of ScrollView
And I would also recommend setting
Recyclerview.setNestedScrollingEnabled(false);

Related

How to remove empty white space at the bottom of the screen in NestedScrollView?

I'm using a NestedScrollView to make the carousel and viewPager scrollable. I added the carousel on the main layout because I need it on all pages from the tab layout. All the pages of the tab layout have only a recycler view in the fragment. The problem is that on the bottom of the screen there is a lot of empty white space that I can't figure out how to remove.
This is the main layout activity xml
`
<?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"
android:orientation="vertical"
android:background="#color/blue_primary"
tools:context=".ui.activity.SplashscreenActivity">
<LinearLayout
android:id="#+id/mainTopBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/margin_padding_size_xlarge"
android:orientation="horizontal">
////// irrelevant code
</LinearLayout>
<LinearLayout
android:id="#+id/mainLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="fill_vertical"
android:layout_alignParentBottom="true"
android:layout_below="#+id/mainTopBar"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab_layout"
android:background="#color/blue_primary"
app:tabTextAppearance="#style/MyCustomTextAppearance"
app:tabIndicatorColor="#color/plan_popular_gradient_1"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/white"
app:tabGravity="fill"
android:clipToPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:overScrollMode="never"
android:layout_gravity="fill_vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:orientation="vertical">
<LinearLayout
android:id="#+id/secondLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="vertical">
<com.gigamole.infinitecycleviewpager.HorizontalInfiniteCycleViewPager
android:id="#+id/carousel"
android:layout_width="match_parent"
android:layout_height="#dimen/featured_height"
app:icvp_interpolator="#android:anim/accelerate_decelerate_interpolator"
app:icvp_scroll_duration="3000"
app:icvp_center_page_scale_offset="#dimen/icon_size_large"
app:icvp_min_page_scale_offset="#dimen/margin_padding_size_xmedium"
app:icvp_max_page_scale="0.8"
app:icvp_min_page_scale="0.55"
app:icvp_medium_scaled="false"/>
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/view_pager"
android:paddingHorizontal="#dimen/margin_padding_size_small"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</RelativeLayout>
`
This is the fragments xml
`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/app_layout_content_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusable="false"
tools:context=".ui.fragments.AppLayoutFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/app_layout_scroll_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
`
This is the recycler view item xml
`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_item_content_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_padding_size_medium"
android:focusable="false"
android:orientation="vertical">
<TextView
android:id="#+id/itemHomeTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:textStyle="bold"
android:textSize="#dimen/text_size_large" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/itemHomeRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
android:focusable="false" />
</LinearLayout>
`
I tried all the answers I could find on stackoverflow (you can see all the attributes on the NestedScrollView) but none of them fixed my problem.

Strange behaviour of recyclerview in nestedscrollview

I have a layout like below. Problem is that the recyclerview height only shows one item.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="#dimen/activity_horizontal_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Live Transactions"
android:textStyle="bold"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_refresh"
android:background="#android:color/transparent"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Strange thing is that when I change the attribute
app:srcCompat="#drawable/ic_refresh"
in the ImageButton to something like
app:srcCompat="#android:drawable/ic_menu_search"
the recyclerview height becomes normal most items show. The ImageButton is on a layout above RecyclerView. Why does this happen?
You have to make your inner linear layout as match parent
<android.support.v4.widget.NestedScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Live Transactions"
android:textStyle="bold"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:background="#android:color/transparent"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Solved it simply by adding
android:fillViewport="true"
to the NestedScrollView
Make the layout_height on the Recycler View to match_parent
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

ScrollView not working in a fragment

i want to make layout scrollable with scrollview but its not working at all.tried to change scrollview with NestedScrollView but the problem still same. this layout used in fragment. put LinearLayout inside the scrollview as a view. can anyone help me to correct my code if i am doing wrong ? below is my xml code
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#android:color/white"
android:orientation="vertical"
tools:context=".ui.jobCalendar.JobCalendarFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.applandeo.materialcalendarview.CalendarView
android:id="#+id/calendarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:headerColor="#color/colorPrimaryDark" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_calendar"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
android:padding="10dp"
style="#style/TextContent.Black"
android:layout_marginBottom="8dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:text="Schedule"
android:textColor="#color/white"
android:textSize="16sp" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/listJob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
tools:listitem="#layout/job_row">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
thanks in advance
Do this
1) Change root layout to RelativeLayout
2) Set height of ScrollView to wrap_content
3) Change height of ScrollView child which is LinearLayout to
match_parent
4)add this line to Host activity of that fragment
<activity
android:name="Activity_name"
android:windowSoftInputMode="stateHidden|adjustResize" />
Finally the xml looks like:-
<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/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:fillViewport="true"
android:orientation="vertical"
tools:context=".ui.jobCalendar.JobCalendarFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.applandeo.materialcalendarview.CalendarView
android:id="#+id/calendarView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:headerColor="#color/colorPrimaryDark" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_calendar"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
style="#style/TextContent.Black"
android:layout_marginBottom="8dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:padding="10dp"
android:text="Schedule"
android:textColor="#color/white"
android:textSize="16sp" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/listJob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/activity_vertical_margin"
tools:listitem="#layout/job_row">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I think you need to get rid of those settings inside the ScrollView attribute.
Basically short it down to
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
Put the rest of the settings inside a RelativeLayout that is included inside the ScrollView like this:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
======== put all the rest of your settings from scrollvide here =====>
<CONTENT> add here the rest of your code </CONTENT>
</RelativeLayout>
</Scrollview>

Scroll two horizontal listview and one vertical listview in single activity

I have to scroll both the horizontal listview and vertical listview in single activity.
Below I have posted a screenshot for that:
activity_main.xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/home_layout_top"
android:scrollbars="none"
>
<RelativeLayout
android:id="#+id/rl_container_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="#+id/inc_ads_horizon"
layout="#layout/ads_horizontal_listview_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_people_know"
layout="#layout/people_you_know_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/inc_ads_horizon"
android:layout_marginTop="10dp" />
<include
android:id="#+id/inc_listview"
layout="#layout/tab_home_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/inc_people_know"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/no_user_posts_item_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/txt_no_posts_available"
android:textColor="#color/txt_common_black"
android:textSize="#dimen/txt_size" />
</RelativeLayout>
</ScrollView>
tab_home_list_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_layout_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<ListView
android:id="#+id/lv_post_home_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="5dp"
android:scrollbars="none"
android:transcriptMode="alwaysScroll"
android:visibility="gone" />
</LinearLayout>
ads_horizontal_listview_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_child"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
people_you_know_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_horizontalscroll_second_child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_horizontalscroll_parent"
android:layout_marginTop="40dp">
<com.steve.thirdparty.HorizontalListView
android:id="#+id/hlv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
I tried with scrollview.It is not possible to scroll.Let me know is there any other ways to solve this issue.
If I scroll vertical listview to top, it is scrolling vertical listview only.If I am scrolling horizontal listview to the top, it is scrolling both vertical and horizontal listivew.But when I am scolling up, horizontal listview is hiden.
You can get the required views by customizing ScrollView & HorizontalScrollView.
Can check this post https://arunbadole1209.wordpress.com/2011/10/03/how-to-make-simultaneous-scrollable-views-in-android/
Use this xml layout, customize item views according to your actual need:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:nestedScrollingEnabled="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- You can define layout manager here also-->
<android.support.v7.widget.RecyclerView
android:id="#+id/ads_horizon"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/people_know"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/post_home_tab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Android SwipeToRefresh - Confilct with RecyclerView when swiping down

So I have a fragment with 2 RecyclerView lists. I want to swipe fragment to refresh those lists but when I scroll one of those lists to see hidden elements SwipeToRefresh refreshes those lists. How to prevent it from that?
Here is my XML layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_fragment">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/main_fragment_swipe_to_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_fragment_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#color/primary_dark"
android:text="Najpopularniejsze przepisy" />
<android.support.v7.widget.RecyclerView
android:id="#+id/top_recipes_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textSize="18sp"
android:textColor="#color/primary_dark"
android:text="Najnowsze przepisy" />
<android.support.v7.widget.RecyclerView
android:id="#+id/latest_recipes_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
Any ideas?
You can consume the swipe down event in RecycleView when it can scroll up.
Just custom the RecycleView and intercept the event when you need.

Categories

Resources