I am looking for an viewpager or scrollview implementation or guidance on how to construct one that mimics that of the Circa News application, shown below.
The ViewPager or ScrollView implementation needs to be able to handle views or fragments(either, not or) of different sizes. Allowing for any size, smaller than full screen and larger also. The focus would be on the top most(top aligned) view/fragment. The scrollbar indicator on the right side is not a requirement.
So far i've found Mark Murphy's analysis on the basic problem, but all of the results don't fit the situation exactly. Link
I ended up finding this answer while looking for something else, but it partly works for the question i posed with a few caveats.
Parchment is a "Horizontal/Vertical ListView, GridView, ViewPager, and GridPatternView". The key part is the ViewPager, but bad part is its not its a listview and does not support fragments as a normal ViewPager would. But you can achieve the same result.
You use Parchment like any other ListView, the key is in the configuration(which i believe can only be done via xml).
<mobi.parchment.widget.adapterview.listview.ListView
android:id="#+id/verticalviewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
parchment:orientation="vertical"
parchment:isViewPager="true"
parchment:snapToPosition="true"
parchment:snapPosition="start" />
The key is "isViewPager", "snapToPosition" and "snapPosition". This enables the list act like a ViewPager. Only difference is the views are from an Adapter's getView() instead of a fragment.
Related
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.
This is not a design question, I have the item designed. I am confused on how to pull it off.
I am tasked with designing a view for Android that has a view of a user's post and the comments under it. The post contains some extra information and widely different design from the comments, but all of them need to scroll in tandem, like a web page would (Oh, how I am spoiled by my years of web dev...).
My current solution is to nest a LinearLayout (at the top of the view to contain the user's post) and a RecyclerView (below the post to display the comments) inside a vertical ScrollView. The information is actually displayed, but the RecyclerView, of course, scrolls independently of the LinearLayout above it and ruins the functionality of the view.
I wish, if possible, to keep the RecyclerView in use
The best case scenario would be to have the LinearLayout with the post scroll a certain amount, and then the RecyclerView take over. However, I don't want to poison my codebase with 200+ ugly lines of code to achieve this, so if this is a laborious task to complete, I would rather look for alternatives.
The first thing to understand is: do you really need a RecyclerView, or even better, do you really need recycling?
If the answer is yes, the way to go is two different item types in the RecyclerView's Adapter (for more details, see here or here). This concept was already present in the ListView: the main difference is that RecyclerView enforce the use of the View Holder pattern. It is not so complex, and, more importantly, is the way the RecyclerView is supposed to solve that problem. Depending on your UI design, you may also want to have different view types for different types of comments (plain text, images, ...). Remember that, when the RecyclerView is included in a ScrollView, the recycling won't work, because all the items in it will be drawn at once to compute the height of the content of the parent ScrollView.
If the answer is no, then you could just create your views at runtime and add them to a parent LinearLayout in a ScrollView. It is really nothing more than a for loop.
A more fancy approach would be to use an ItemDecoration for the user's post, but I don't see any specific advantage in this case.
I'm new programming in Android and i have many doubts about what type of classes can i use in my first app.
I want to do a level menu like cut the rope or angry birds. Only a title and a slider menu.
I think that can do with the two classes, but I'm not sure which is better, can you tell me the difference and which is better to use?
Many thanks.
ViewPager allows you to flip between pages of data (between views). You supply an adapter to generate the pages that the view shows.
But HorizontalScrollView is a container for other views that you can scrolled through, allowing it to be larger than the physical display.
I would go with horizontal scroll view.
EDIT : See FoamyGuy's answer in Angry Birds like scrolling menu where he exactly explains how to achieve such effect.
Apology if this has been asked before, but I've tried googling the topic without any good result. Basically I'm trying to find a replacement for Gallery widget which Google has decided to deprecate. So far I have the following candidates:
ViewPager. Unfortunately (as far as I know), you can only display one View at a time. I know someone has posted a workaround for this here: https://gist.github.com/devunwired/8cbe094bb7a783e37ad1. But I'm having problem with this approach. On my phone, three images are shown (horizontally). The most left & the most right are static, while the middle one is scrollable (like what ViewPager should do). i.e. the most left & most right image doesnt scroll as I scroll the ViewPager. So I have to turn down this solution.
GridView. Seems good, but it seems like GridView is designed to be scrollable horizontally & vertically. I just want one row, and scroll horizontally. As far as I know, Gallery is not designed with this in mind.
HorizontalScrollView. Another one that Google has suggested in the Javadocs (apart from ViewPager). Seems like a good one to use, but... if i understand it correctly, using this approach all the contents are going to be instantiated up front. There is no lazy loading..
So I'm puzzled right here. Seems like the best solution is to either use ViewPager with only one View at a time (undesirable for what I want), or stick with Gallery.
What do people think??
Thanks in advance!
android.support.v4.view.ViewPager is the definitive answer.
You can display any number of pages (Views), it all depends on the PagerAdapter. It has a method .getPageWidth(position), which gets called for each page. If it returns 0.5, for example, the page will only be half the width of the ViewPager.
Don't stick with Gallery, as it has memory leak issues.
What I functionally need is a Vertical ViewPager with GridView.
So every page of the ViewPager should have a GridView, but the ViewPager is horizontal.
So there are two possibilities:
Rotate the ViewPager with GridViews
Create a GridView that shows the items in pages
The GridView should show 0-20 when the user scrolls 20-40 etc etc.
Does anyone have a solution for this?
I have checked this link, but I cannot use it cause of legal reasons.
Sounds like what you really need is a vertical ViewPager. Although Android only provides a horizontal one, there's nothing that prevents you from implementing it yourself. Get the ViewPager source code and modify it to detect swipes up/down instead of left/right. The source is distributed under Apache 2.0 license, therefore you have full rights to create derivative works without having to distribute the source of it.
There will be very few places to change, specifically, methods related to computing the swipe direction/slope (up/down instead of left/right) and methods related to layout computation (using height instead of width and layout pages below each other).