Scrolling two views together - android

I currently have one Scrollview which contains a table layout and one
list in my activity. Now my problem is that I wanted to move both of
them(Scrollview and list) together and with proper synchronization...
So if scrollview is being scrolled then listview should also scroll
with the same distance, and vice versa...
Thanks in advance..
Abhishek

create your own scrollview and override all scrolling related function to do your custom actions.
In the listview you can make use of
[AbsListView.OnScrollListener][1]
to make magic :-)

Related

Scrolling entire layout with a ListView and another View

I know that is not a good practice put a ListView inside a ScrollView, that's why I want to figure out what kind of solution can handle this.
Look at the image below:
There's a block with some stuff on the top and there's a ListView below, and all of this scrolls with the entire layout. So, the question is:
How do I achieve this?
You should have just a ListView and set a headerView to this ListView to achieve what you want.
Use header View:
ListView below scrollview in Android
or Sticky List Headers if you want to make them stick on top of the listview:
https://github.com/emilsjolander/StickyListHeaders
or use different ViewTypes with your own Adapter implementation:
Listview: Only one list item with multiple textviews
Why do you assume the reviews shown there are in a ListView? To me they just look like a handful of custom Views stacked on top of each other, not an actual ListView.

Scroll another HorizontalScrollView though one is scrolling in android

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.

scrollView linearlayout and listview

I'm doing an android app, and I just want to have an scrollable layout, but inside of this layout I want to put some textView and 2 listView, and this is my problem, the listView.
I need to include this 2 listview on the layout and this is obligatory need to be scrollable, and I googling and all I found is negative.
how can I put 2 listview on scrollView?? is not possible? and if its right what can i do? Which is the alternative that I have? I really desesperated because I spend all day!!
con someone say me an example of this?
really thanks!
ListViews shouldn't be placed inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all get handled by the parent ScrollView. However you can add views you want to be scrolled to the ListView as headers or footers.

Scrollview inside listview issue in android

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

SimpleCursorAdapter within a ScrollView

I'm having abit of an issue and i'm not too sure how to go about solving it.
Essentially i have an activity which has a base xml layout of ScrollView and i want this activity to list some results from a Cursor. So i thought i'd use SimpleCursorAdapter... however when i got it all set up it appears that the ListView that the SimpleCursorAdapter goes into doesn't play nice being within another scrollable layout element.
I've sorta got it working programmically but i'd much rather use a ListAdapter as it will make each list entry look like a button and keep it inline with the design of the rest of the application and can handle the ids of each item and where to send the user upon clicking.
So my question is this: is there anyway to either make ListView show all the items such that it never needs to scroll, or can i change the ListView to something like a LinearLayout?
I hope that makes sense!
Any help / insight / ideas are welcome!
Cheers!
You can NEVER use a scroll view and a ListView together. Its a mess! and illogical as well.
Here are some of the approaches you can use:
Theres no screen big enough to show all the content of you listView you can try wrapping up your content but as I said it won't help as scroll view and list view don't work together. So you can either remove your or
If your list items are simple you can dynamically add your views to LinearLayout with specified location
Another tip I can give you is you can always use an relative layout and place your listView alignParentBottom="true" and emit the scrollView approach this will make you listview alwyas scrollable.
It doesn't really make sense to have a ListView inside a ScrollView at all. The ListView implements it's own scroll function so it should not be used in conjunction with a ScrollView anyway.
You should rethink your UI design.
I agree with Shardul; trying to put a listview with a scrollview will make it impossible to scroll. Have a look at the links below to see what you can accomplish with just a ListView -
a.
custom backgrounds info.
custom adapters

Categories

Resources