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?
Related
I'm a flutter user trying out kotlin dev first time, but im kinda confused what the best alternatives for this type of layouts are.
I understand that I use recyclerview for a dynamic number of items. And since theres two dynamic ones (one for number of sets, one for each exercise). Do I use two nested recyclerviews?
It really depends what you're doing here. A RecyclerView is basically a list, so it's a good choice for a scrollable set of items - which it looks like your Exercises are. But how do you want to display those weights?
It's possible to make them scrollable, so some of them aren't visible on the screen (the categories on the Play Store act like this). For that you would need a nested scrolling view of some kind - could be a horizontal RecyclerView, or it could just be a ScrollView wrapped around a LinearLayout you throw views into.
But the other option you might want, is that for each Exercise, all of its weights are visible in a grid of some kind. No scrolling, all there up-front to see and poke at. So the first question is which of those do you want?
I'd assume it's this version - where you can easily visualise the contents - in which case you're not talking about nested lists, it's just one list, and each item contains a grid you can add things too. For that setup, there's GridLayout, TableLayout, and ConstraintLayout Flow (which acts like FlexBox if you're familiar with that). So in the layout for an item in your list, you have a container for stuff, and you put the stuff in it, and the container expands vertically as needed
Being objective, my goal is simple (or not), drag a recycler's item to other one in my activity.
The scenario is the following.
I have a list of items, let's call them sections, and inside a section another list of items, of another type, the elements.
I want exchange the elements between the sections. The list of sections isn't fixed, can be changed adding and removing a section, but hasn't any movement behavior. The elements also can be added and removed from a section, but have this reorder approach.
I've found some strategies with fixed "section". Here is an example. This one uses drag and drop to make the exchange. But it's too simple. For example, don't consider the need to scroll recycle when the dragging reaches bottom or top of visible elements. That's because it has only two lists. Does Drag and Drop have this behavior, forcing the scroll?
Is there any way to do this using the ItemTouchHelper? If so, how would it be? ItemTouchHelper seems better, 'cause considers the scroll problem and has a more intuitive reorder animation.
If you think of a better approach than using recyclers, feel free to indicate such strategy to me.
You use drag and drop for the dragging and dropping, the scrolling and such you'd have to make yourself using the appropriate events in the OnDragListener.
Currently, I am exploring the option of displaying data from a database by swiping left to right and also allowing users add and remove data from any position in the data array.
I found out that there are 2 possible solutions to do this. One is a RecyclerView with horizontal scroll and the other is a ViewPager with a FragmentStatePagerAdapter .
Which is more efficient? In terms of Memory usage and Ease of implementation?
Thanks.
I would say they are comparable in terms of memory usage and ease of implementation. Where they differ most is in the interaction they provide to the user.
ViewPager is designed to show one item at a time. The visible item takes up full width of the ViewPager. You can only swipe one item at a time and scrolling always snaps to showing one item in the centre – you're never left in an in-between position partially showing two items.
RecyclerView with a horizontal layout manager on the other hand can have items of any width – you could be showing many items at once or you could have items wider that RecyclerView's width or you could match their widths to mimic ViewPager. You can freely scroll – you are not limited to one item width or RecyclerView's width, you can do a fling gesture to scroll big distances. And there's no snapping – when the scroll finishes there's no aligning items to the centre or any of the sides.
As you see there are a few differences. I would recommend you to choose your widget based on the UI you want to achieve. If you want ViewPager's behaviour (one item visible at a time, swipe limited to one item and snapping to show the full item) then go with a ViewPager. It's possible but not trivial to replicate this behaviour using a RecycleView. I would definitely say it is way more difficult to use RecyclerView if you want to make it behave like ViewPager. Conversely it's pretty much impossible to customise ViewPager's behaviour, so if that's not what you want then you definitely should use a RecyclerView.
In term of ease of implementation (this is just my own opinion),
ViewPager is good for displaying the list of data that is not required often add and remove since PagerAdapter can't notify each specific item that it is removed or added it can only call notifyDataSetChanged() which notify that all set of data has been changed. Therefore, it is hard to handle the animation when the item is added or removed.
While in RecyclerView, RecyclerView.Adapter has methods like notifyItemInserted(int position) or notifyItemRemoved(int position) to notify that specific the item is added or removed and, the animation when item is add or remove is already handle when you called those method.
Moreover, right now it is very easy for RecyclerView to mimic the ViewPager behavior by using SnapHelper. There is PagerSnapHelper, and the behavior of ViewPager can be obtained with just a few lines of code. You can contact me if you want the code.
There is no comparison between this two. basically in ViewPager you can scroll only one item at time (either left or right), and in RecyclerView you can scroll to any index. it all depends on your requirements how you want to use it. you need to develop fragments for ViewPages, one for each page. as in RecyclerView you will have a item which will be used by adapter. both of them are easy to implement. there are numerous examples on both of them, you can have a look and get started.
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
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...