pintrest like android scrollview
Basically I am looking to have two list views which scroll only together (not separately) when I scroll the screen. (Like if they where in the same scroll view)
Each if the list items of course most remain clickable. Each if the items in each list can have different lengths, so no I can't have a single adapter.
Thanks
The Trick is ListView withing a ListView. You need to have a main listview and then a layout that holds other two listview. The subsequest scroll can be sync between those both using onScrollListener and sync between them. Its quite a project by itself but you could give a try.
Another way is to build a custom view which you want to display as pInterest, might take more than expected time.
there are a lot of libraries for that, here are some of them
https://github.com/vladexologija/PinterestListView
https://github.com/chenyoca/pinterest-like-adapter-view
Related
Am trying to create a page with a scrollable list. Features would be a normal list to remove item by clicking on it. Number of items in that list are limited and added dynamically by user. You can consider a to do list as example. Now which would be a better approach to implement it? Recycler view with data bound to its adapter? Or the normal linear layout with items added as children at run time?
My current implementation is recycler view. But,I found it lagging and animations are not performing well. So a linear layout is auto animated by specifying it xml -- by setting animate layout changes to true.
FYI data is local and syncs in background.
Never use a LinearLayout for anything longer than a single screen. The whole point of ListView and RecyclerView is to efficiently reuse views instead of needing to hold things in memory when they're not visible. Maybe you can refine or reask your question so people can help you with whatever difficulty you're having with animations, rather than avoiding the issue.
I will need to create cards layout mimicking cards found in Google Now. To do so, I've used a RecyclerView and each row as both the header and item. Pretty skeptical with this approach however.
The problem I'm facing is to mimic the swiping behaviour. Swiping at the header will also move the entire card (header + items) together.
To do so, I managed to edit the SwipeDismissRecyclerViewTouchListener and the adapter to remove the affected items. But after that, the visual would get clunky whereby remaining items would have random empty spaces in between or height that does not match.
How and what is the correct way to approach this? Should I instead use another way to populate the cards?
I know how to populate a ListView or any other list types, but now I am facing an issue where I should implement a ListView in a ScrollView. So, I decided to use a LinearLayout ( myLinearLayout.addView( adapter.getView(position, null, null) ). As you can see, I am retrieving data from adapter and adding as a new view to my LinearLayout. Everything is working, but if the list is being populated with 30+ rows the application freezes. Each row contains an ImageView and this way the virtual machine can't allocate enough memory.
How I should recycle linearlayout rows?
It doesn't look like a good idea to put a listview inside a scrollview. How are your users gonna use that ? Which gesture will scroll the scrollview and which one will scroll the listview ? It's not going to be usable.
Android components are well designed, you should really consider sticking to a listview that every one knows how to use and is pretty well optimized.
If you have troubles displaying many images in a list, refer this docs from google.
Once you populate the row into a linear layout the views aren't recycled by the adapter. As you wrote its also not possible to have to scroll components one inside the other. Why do you need to show list inside scroll? Did you considered populate the list "on top" of the scroll view? For example in a different fragment?
I am trying to create something like (very poorly created in paint) in the image below:
I have only 4 items, and it won't be more. the items contains two textviews. But when you click on an item, i want it to expand, (like item 2) to the bottom with three extra buttons. It would be really nice if there would be some nice expand animation. I don't want this list to be scrollabe, it just need to fits in my screen. And only one can be expanded.
I think there are two options, but maybe i am missing something.
1) Create an itemlayout.xml, containing an linearlayout or something containing the extra buttons, set to linearlayoutbuttoncontainer.setvisibility(View.GONE). And then build a switch, which closes the others than the clicked one, and set the visibility of the clicked item to visible. This would be fairly easy to build i guess, i don't foresee a lot of problems. But is it possible creating an animation or is there only a sudden screen change?
2) expandable listview, with the buttons in the expandable item. I know its possible to make only one item expanded, by rembering the expanded one and closing it again. But is it possible to make it like this, with the buttons in the expandable part? Actually i've never used an expandable view.
Anyone know what the best solution should be?
Thanks
I would recommend using an expandable list view for this, as your second option described. For this type of list you can use a expandable listview adapter, describded here:
http://developer.android.com/reference/android/widget/ExpandableListAdapter.html
This adapter has both a getGroupView(open/close items) and a getChildView method in which you can inflate your layouts, or manually set them up. If you have used ordinary listviews I'm sure this wont be a problem for you, since it's basically the same operations.
This means you should probably inflate your childViews with a LinearLayout containing three buttons. Then you have to implement functionality for your collapse/expand logics by keeping track of which item index is opened.
I did this tutorial when I first started out with exp.list views, I found it helpful:
http://android-adda.blogspot.se/2011/06/custom-expandable-listview.html
Good luck!
You gotta check this http://udinic.wordpress.com/2011/09/03/expanding-listview-items/ it works neat. If you got any more problems, do ask...
I have a LinearLayout with a nested listview which looks like this:
<LinearLayout ... >
<LinearLayout>
</LinearLayout>
<ListView>
</ListView>
</LinearLayout>
The problem is that the listview owns the scrollbar (so only content in the listview is scrollable) but i actually want the parent LinearLayout to own the scrollbar (so making the entire content scrollable).
Wrapping parent ListView in a ScrollView hasn't been successful because the ScrollView doesn't recognize ListView height (which looks like is rendered at running time)
Thanks
Edit: SOLVED My perfect solution was using a MergeAdapter, as advised by Barak
You can use CommonWares MergeAdapter which allows you to define views and list adapters, pour them into the MergeAdapter and get a single list adapter out, containing everything you poured in, and it scrolls as one list.
A previous answer about MergeAdapter I gave with some instructions is here
You could replace the Listview with a Tableview instead, as long as the listview does not have too many items in it. You can still use a childview with the tableview in much the same way as the listview, you just won't be able to databind it in the same way as you can with a listview, and the items won't recycle either.
Since the listview is designed to contain more items than can be displayed the height will never exceed the screen size (best case) which is the intent of the control, though I suppose you could force it to be larger that seems generally like a bad idea for a lot of reasons.
I suspect what you should do is either create a custom listview adapter, and based on position in the list create the view you want, this would allow all items to scroll like you want.
Listview with different view types per row
This may or may not work depending on what exactly you are trying to do, otherwise you might just want to add views to a linear view inside a scroll view san's the listview.
It just depends on the use case (how many items in the list view, memory issues etc) and what the purpose of the other views are.