I have a ListView inside of a ScrollView - but my issue is that I don't want the Listview to scroll, instead I want the listview to be fully expanded and just scroll the ScrollView up and down to see the items of the ListView. Can someone recoment a solution?
Here is my layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
>
<ListView
android:id="#+id/user_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:visibility="gone" />
</ScrollView>
P.S. I know that this is bad practice but I need this thing anyway
set this property in your scrollview android:fillViewport="true" it will work
two scrolling views cannot be inside one another.
Follow the following link:
ListView inside ScrollView is not scrolling on Android
You can consider this. But the ListView's height must be hard coded and it does recycling which slightly deviates from your requirement. But ListView without recycling, as you mentioned, is not a good practice. So try to achieve the thing with recycling as described in the above link.
Related
Im creating RecyclerView and ListView inside ScrollView and im getting problems with the scroll.. The scroll is Jerking (unable to get smooth scroll), I know its the problem with the RecyclerView inside the ScrollView, because layout is scrolling without any problem when swiping until the ListView exists but once RecyclerView items enter the layout it starts to jerk( only scrolling with the finger, no proper scroll when finger is taken off). Here is the code in the xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/lv_home_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/colorWhite"
android:dividerHeight="0.5dp"
android:visibility="gone"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycleView"
android:background="#color/colorWhite">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
Nested views that scroll along the same axis have always been
problematic on Android. Recently Google has added nested scrolling
support. In order to have this on older platform levels, you should
use the views in the support library like NestedScrollView and
RecyclerView.
ListView does not work with wrap_content as its height. You can do
this with RecyclerView if you have the latest version of the
RecyclerView support library. Besides, you are already using RecyclerView in one place, you might as well use them exclusively.
ListView is not really meant to be a "drop down". Perhaps you should consider a Spinner instead.
I have it finally.!!
Just add the following line of code in you class where you are calling the RecyclerView
mRecyclerView = (RecyclerView)tmpView.findViewById(R.id.recycleView);
mRecyclerView.setNestedScrollingEnabled(false);
It works for me!
Over the past few weeks I've been learning to use the RecyclerView. I need to implement a horizontal list, ie, that by turning the device in landscape mode like so:
I found the best solution for this (how to create the horizontal displacement of RecyclerView, here), but encountered another problem. The item RecyclerView was larger than the height of the device (in landscape, horizontal), so I need to create a vertical and horizontal displacement, simultaneously.
I looked at the Android Developer methods for the LayoutManager class, but my skills are not high enough to understand most of the methods. I also tried putting a RecyclerView vertically inside another RecyclerView horizontally with all the content, but I get error:
IllegalStateException: RecyclerView has no LayoutManager
To rememedy this I removed all <View ... /> elements from the XML file, but this does not give any results.
To clarify what I am asking: is it possible to have my layout scroll both horizontally and vertically, and if you could explain how I would appreciate it.
I was so angry about all the problems that had tended with the application that had not thought about the easiest solution.
In a RecyclerView consists of two XML files, the main one where the RecyclerView is declared and another with content.
The simplest solution was to introduce the RecyclerView within a ScrollView. So I can move all items at a time thanks to ScrollView vertically and horizontally I can move the items thanks to RecyclerView in landscape mode.
activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/cardIn_margin_ext">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideInset"
android:scrollbars="horizontal" />
</ScrollView>
The accepted answer did'nt work for me. I had to use the HorizontalScrollView instead of simple ScrollView.
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/cardIn_margin_ext">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideInset"
android:scrollbars="horizontal" />
</HorizontalScrollView >
I have a data set and I need to show them using ListView and TableLayout in same xml file.As both ListView and TableLayout are much longer,I decide to use scrollView. I knew that android scrollview can only have one child. So I Coded as follows.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="8">
<LinearLayout
android:id="#+id/showClaim_layout2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/claimList"
android:layout_margin="5dp">
</ListView>
<TableLayout
android:id="#+id/showClaimTable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFEBCD"
android:layout_margin="5dp"
android:shrinkColumns="0">
</TableLayout>
</LinearLayout>
</ScrollView>
When I run the program it's ok. I mean page is scrolling. But it doesn't work as I expected!I need to show all the list element and after end of the list, tableLayout must be show.If the screen size is not enough then we can scroll the page and see the data.
In here ListView does not show all elements of the List and TableLayout show all tableRaws inside ScrollView.
Can anyone tell me that where I got wrong or any other way to do my task easily.
Thanks.
As far as I know, you should never put a ListViewinside a ScrollView, since they implement their own scrolling behavior. Consider changing your design.
"I knew that android scrollview can only have one child." Correct but you forget that that one child should have a height of wrap_content.
Also #haint is correct ListView has its own Scrolling Behavior. Still try android:layout_height="wrap_content" for your LinearLayout
I think you can fix it by using the
layout_weight
set layout_weight for your ListView to 1 and for TableLayour set it to 0;
Be sure after changing set layot*:height to 0dp;
You can check below articles.
first-
second-
I have a RelativeLayout and below that i have a ListView. I have to place these inside a ScrollView. Any help will be deeply appreciated.
You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView
ScrollView can be set only for a single Layout. So place the widgets which u want to scroll in a single layout as below:
<ScrollView
android:id="#+id/scrView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="#+id/rltvLyt"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/lstView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp" />
</RelativeLayout>
</ScrollView>
Don't do it. What exactly are you trying to achieve? It had been mentioned here (and everywhere else) this is not a good idea because the scrolling mechanisms get confused as they both want to scroll. Ignoring you however have a listview that is massive then you have missed the major performance gain of using a listview and might swell be using a table layout and add rows.
I am not able to scroll in a scrollview which contains a listview and is filled dynamically as I get data from the webservice.
I am able to do scrolling in emulator through mouse wheel, but in avtual device I can not scroll the list.
The attributes of scrollview are
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:fillViewport="true"
android:orientation="vertical"
android:padding="6.0dip"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="5000"
android:scrollbarSize="20dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="2dp" >
<ListView
android:id="#+id/listbox_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="599.84"
android:minHeight="250dp" >
</ListView>
</LinearLayout>
</ScrollView>
Please help me soon
by just looking at the layout_width and layout_height of your elements, it's clear that your scrollview will not scroll. unless you have a fixed height listview, never put a listview inside a scrollview (or in this case, a listview inside a layout that sits inside a scrollview).
I don't have any links to back this up right now, but it's not possible, and a well-known 'problem'. If you google a bit, or search here on SO, you'll find a number of topics covering this.
The problem arises in most cases when you have a scrolling view inside another scrolling view in the same direction. Consider the following example:
You have Two lists inside of a ScrollView.
Both lists are exactly one screen tall.
How do you scroll down to the second list?
When scrolling, how will your layout know if you are scrolling the list or the container?
This is basically the question that is the cause, and the only official solution is that it is as it should be, and there won't be a fix. Usually it is enough to have either a ListView or a ScrollView, but I have faced cases when you must have a listview in a scrollview (in my case a client wanted an iPhone-like datespinner in a scrolling page).
I solved it by using a FrameLayout, containing a custom ScrollView, and a ListView on top of that. Then in the code for the custom ScrollView, I added a line in the onScroll method that updated the top margin of the ListView, to psuh it upwards or downwards as the user scrolled. Surprisingly it worked.
NOTE: remember that:
The ListView handles its own scroll. If all you need is a scrolling
list, you do not need a ScrollView.
If you need a layout with a list and space for buttons or other
views, consider creating your layout so that the list only covers
enough space for you to fit your other views below/above without
scrolling.
Add following in your linear layout
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"