Android ScrollView layout problem - android

I have several ListViews in a LinearLayout. It's listing things by day, so I have a TextView containing "Sunday:" followed by a list of items, followed by a "Monday" TextView, etc. Works great, but doesn't fit in the screen. So I added a ScrollView as a parent of the LinearLayout. Now it scrolls, but the ListViews all have room for 2 entries, whether they have 0 or 3 entries. Something about adding the ScrollView parent caused the ListViews to not size dynamically. I tried calling requestLayout() on the ScrollView after the list adapters had filled their views, but that didn't do anything. Any ideas?
Edit:
From http://www.anddev.org/viewtopic.php?p=25194 and other links it seems that ListViews inside a ScrollView are not handled correctly. Anyone have a good suggestion for implementing a list-of-lists?

I'm interested in that topic too, so I did a bit of research. First: Never put a ListView in a ScrollView (as you found out yourself). Unfortunately googling this problem doesn't lead to any solutions, so I tried my suggestion from my comment above.
I implemented a custom ListAdapter and put the ListViews into one parent ListView. This doesn't work (leads to the same problem as with a ScrollView). Speaking to the guys on the official android-irc #android-dev on freenode, they told me that putting ListViews into a ListView is as bad as or even worse than putting them into a ScrollView. Unfortunately they also couldn't help me with the problem.
There seems to be only one way to achieve what you want to do; see the answer on this similar question Scrolling with Multiple ListViews for Android . The idea is to merge all ListViews into a single one by a custom adapter and to insert some kind of headers between entries. This is absolutely doable but might require some special effort.

I know it's late to answer this right now, but still - it may be useful to others who arrive here in case of similar problems.
I'd suggest that you use an Expandable ListView for this. It would solve all of your problems.
You can have the main/parent names as that of week, and when you expand it, you would have the list of entries for that particular day/week/whatever.
Also, you wouldn't have to worry about scrolling as it is taken care by android :)
If you DO try this, then please let me know if this works out for your problem
Try searching for examples on Expandable ListView.
edit:check example here - http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html

Related

Multiple recyclerviews (gridlayout and horizontal linearlayout) inside one view

I am trying to achive this:
First I tried by putting all my recyclerviews (with WRAP_CONTENT) inside a nestedscrollview. That worked, but the performance was awful. Then I tried to set a height for my recyclerviews, that was a lot better (especially the first gridlayout and the horizontal linearlayout loaded very fast), but still had the problem with the dynamic "category" part.
Now I am trying to put all my recyclerviews inside a single recyclerview with different viewtypes. Since that is a pretty big deal (I need to refactor a lot of code because I have diveded every area from the screenshot inside a single fragment and now I need to put all that code inside an adapter) I wanted to ask if I can actually expect any gain from this, because in the end its again a "nestedscrollview" (made by myself, but...). Or if there is some other "best practice" way to achive this layout.
Thank you
Edit:
As expected this didnt do the trick neither. When just the two first recyclerviews are added as viewtype it scrolls and loads smoothly. But as as soon as I try to add the category items (below the category), I notice a lag and especially when selecting multiple categories and scrolling fast up, there is noticable lag. I guess I will have to change my layout and move the category selection part inside a separate view, just need to come up with a user friendly solution. But its acutally quite dissapointing that, in my opinion such trivial task, laying out multiple tables, is such a pain in the ass on android.
I didn't manage to get it working with standard android stuff.
Now I am using epoxy from airbnb ,and I have converted all my views from nestedscrollview to the epoxy recyclerview. Its a great library, and airbnb use it too for all their views.
Nevertheless it's sad that the android dev team doesn't address this problem and provide a solution besides the info "don't nest multiple scrollviews(recyclerviews) that scroll into the same direction".
You can use Recyclerview in recyclerview.
https://irpdevelop.wordpress.com/2016/02/10/horizontal-recyclerview-inside-a-vertical-recyclerview/
And make sure to use multiple view types.

Stack up views in RecyclerView

I'm actually a little bit confuse. I had to refactor some old code, and i've ended up with the place where hundreds of views which need to stack up on each other are just adding to RelativeLayout with
parentView.addView(m_view, 0);
Which is kinda sad. So i wanted to rewrite it as a RecyclerView elements, but instantly faced problem of their order. I can't find any examples on how to do it, maybe i google it incorrect or smth. I've tried to write my own LayoutManager, but i couldn't find any obvious way to achieve my goal.
Is there maybe another way? Or it's not that hard to order childs in RecylcerView like they are in RelativeLayout?
As was suggested in comments, i've added an image to see how i want it to look
As you can see views are lying on each other, that's what i want to achieve
I refer you to use this library.
SwipeStack : A simple, customizable and easy to use swipeable view stack for Android.

Facebook Android App News Feed Layout

I am trying to implement a vertical listview with horizontal scroll on each item just like the facebook newsfeed. Suggested apps can be seen by scrolling to right and some part of next item is also visible.
here is the screenshot :
http://i.stack.imgur.com/7JRfM.png
So I am just stuck here and don't know how to proceed.
You're probably going to need to write some custom code (which is a pretty good rule of thumb whenever you're trying to do something Facebook did on Android; they do some crazy stuff).
I don't believe you can nest ListViews in Android. There is "ExpandableListView", which lets you expand items to show more, although this isn't quite the same thing.
I would advise to just create a vertical ListView, and have the items be horizontal LinearLayouts that you can inflate yourself. You can also try making them horizontal ScrollViews (although I think this may have the same limitation as using nested ListViews).
Good luck!

Columns as many as 24 and rows as many as 100 in the listView

The idea is that I want to make a view which can have many columns so it needs the horizontal scroll and as I am using ListView so the the intention is also for the vertical scroll. I do not want to use ViewFlipper kind of stuff.
And another reason I am using ListView and not TableLayout is because I am concerned about the performance. With listview we have adapter and recycler which makes the performance really good.
Anybody Any clue please??
Edit: I have changed the caption of my problem for better understanding of the issue.
I came to the conclusion that I cannot make the kind of design I am trying to do with the ListView, so I should rather stick to the Tablelayout design only and use the Async task for performance. But I have to work on this. Once it works, I will put my design here.

How to fix child in views

I am facing problem in fixing the child in particular place
in views or layout.
Can I fix the child at the starting and ending of Layout directly ?
Can I fix the child at the starting or ending of the view directly ?
Are you sure that you understand the different types of layouts and what is their intended purpose?
About the layouts, please look here: http://developer.android.com/guide/topics/ui/layout-objects.html
About placing child views in another view, look here: http://developer.android.com/reference/android/view/ViewGroup.html
P.S. You seem to ask lots of questions, without having a good perspective for Android. Maybe reading a book or two about the platform will be better than trying to have every little problem in your project solved here.

Categories

Resources