I have a layout which has some some TextViews and ImageView on the top of the screen and a GridView. You know GridView has own scroll and GridView's ScrollListener says me firstVisibleItem, visibleItemCount and totalItemCount.
My problem is that when I want to scroll my layout from the top, I have to put my all layout into ScrollView so my GridView(ExpandableHeightGridView) does not get the correct itemcounts. If I dont put a ScrollView, I can't scroll from the top.
How to deal with this problem? How can I scroll my all layout from the top.
Remember, my major problem is getting wrong itemcounts. I want to load more items when scroll reachs at the bottom so I have to read itemcounts.
Thank you to all.
It's not a good idea to have two scrolling containers one in the other. I'd expect the GridView to misbehave when it's inside a ScrollView.
The cleanest solution to your problem would be to use the concept of ListView's addHeaderView(). As GridView doesn't support headers though, you'll have to use another Google's class, namely HeaderGridView: https://android.googlesource.com/platform/packages/apps/Gallery2/+/idea133/src/com/android/photos/views/HeaderGridView.java
Related
I have a layout with a linearLayout (top layout) and a listview under this.
What I want to do is like the phone app in Lollipop:
With the scrollbar I can scroll the contact list (top layout doesn't move)
When scroll the list with the finger, first the top layout is scrolling and once it is not visible anymore the listview scroll. When the top layout is visible the scrollbar doesn't move.
Someone has any idea how to do this trick?
What I'm thinking :
I can add the top layout to the header of listview, but the scrollbar take count of the header. And if I scroll with the scrollbar, the top layout will scroll
Trying to set a scrollListener to the listview, and translate the top view, but don't think it will be good and the scrollY is not available for listView
I think I can do something with a scrollView for the root layout, but I know it is not good to put a listview inside a scrollview.
I don't find any proper way to do this kind of feature...
EDIT: To be more clear, I want to translate the listview before I'm able to scroll the listview itself. Problem is when translate listview, the listview height will not expand.
I am also getting this problem in version 5.1 in lower version it's working fine.Try to use in 5.0 As it STABLE verson, also check another scrolling bug in 5.1 in this link here I could not comment so posting this as answer.
What I need is something like this:
If I use 2 gridViews, they will scroll separately. So I put 2 gridViews into a vertical LinearLayout, both gridViews have fillViewport set to true, and I put this LinearLayout inside a scrollView. But it doesn't work, the scrollView doesn't scroll to the full extent of the 2nd gridView.
I found this: Gridview height gets cut
Looks this can solve my problem by making the gridView grow its height, but as the comments say, this solution is not memory efficient, as it foregoes the cell recycling, and can cause crashes.
Is there any other better way to implement this?
Try ListView with custom items instead. Top grid may be set with setHeaderView method, and bottom grid should be replaced with a set of items to show. This is both default and memory effecient way, it loads only what you show and allows scrolling.
I have two HorizontalScrollViews. If the user scrolls one ScrollView, the other ScrollView should also get scrolled. I am new to android and I wonder to know how can I achieve this?
If you want your two different scrollviews to scroll at the same time it means you only need one scroll view in which you cand put the content within the ones you have now. Try do make thinghs as simple as you can
Extend HorizontalScrollview like this: https://stackoverflow.com/a/6462630/1124160
onScroll in first ScrollView: http://developer.android.com/reference/android/widget/HorizontalScrollView.html#scrollTo(int, int)
Scroll the second one.
If your have number of items save in both HorizontalScrollView , then create a GridView and give number of columns equals to element in one HorizontalScrollView. In this way you can achieve your goal.
I want to learn how to solve this problem. I want to have a Horizontal scrollview with the scroll blocked (the user should not be able to scroll it) and inside that horizontal scrollview i want to have another horizontal scroll view, and this scrollview must be able to be scrolled by the user (it haves more content that the width of the screen).
Is it possible to do it?
I tried using this on the parent horizontal scroll view:
((HorizontalScrollView) view).setHorizontalScrollBarEnabled(false);
((HorizontalScrollView) view).setEnabled(false);
((HorizontalScrollView) view).setFocusable(false);
((HorizontalScrollView) view).setFocusableInTouchMode(false);
and this on the child horizontal scroll view:
((HorizontalScrollView) view).requestFocus();
It is not working, the child appears to have a scroll bar, but it cannot be scrolled.
How can this be solved?
PD: I know that this is not a good practice, but I want to learn how to achieve this goal.
You should never use a
HorizontalScrollView with a ListView,
since ListView takes care of its own
scrolling. Most importantly, doing
this defeats all of the important
optimizations in ListView for dealing
with large lists, since it effectively
forces the ListView to display its
entire list of items to fill up the
infinite container supplied by
HorizontalScrollView.
http://developer.android.com/reference/android/widget/HorizontalScrollView.html
UPDATE:
Since you may be forced to use a two dimensional scrollview, you may consider using this:
http://blog.gorges.us/2010/06/android-two-dimensional-scrollview/
I haven't used this but it may be a reasonable approach.
you can do it. But you have to handle child layouts in scrollview i.e ScrollView can host only one direct child.
I am adding a listview inside a scrollview in xml that xml(Screen) is loading from the middle screen. In my design I have a top part like a textview and a list view and middle part like editext and bottom part like button. Page is loading from the middle part. If it scrolls I can only see the above part. I want to load the page from above part. Can anybody tell me what the problem is and how to resolve it?
Thanks
Use android:fillViewport="true" as an attribute in your scrollview tag and it will fill up the screen.
Actually there is no need to use ScrollView with ListView. Use ListView only, you will be able to scroll the items in a ListView.
You should never use a ScrollView with a ListView, because ListView
takes care of its own vertical scrolling. Most importantly, doing this
defeats all of the important optimizations in ListView for dealing
with large lists, since it effectively forces the ListView to display
its entire list of items to fill up the infinite container supplied by
ScrollView.
found it here
using smoothScrollTO(0,0) to fix the issue