Alternatives to android.widget.Gallery (not the Gallery app) - android

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.

Related

Firebase with viewpager

I am currently building an app using firebase.
I have an activity in which the background and UI are the same, but the page has only the contents that change inside according to the date.
It`s kind of some diary app.
I am worried about whether I need to ViewPager or not to use ViewPager, but if I have saved it somewhere and clicked on that date, I need to display the contents with setText(). I'm not sure about that how to do more optimization.
And when I scroll horizontally across the screen, I want to see the pages change with swipe-animation. Do I have to use viewPager? I mean I use one page but I want to give a fake animation effect as the page looks. If this helps optimally.
Anyway, So I'm looking for an example that uses viewPager with firebase recycler-view, but it's a bit hard to find. Is it better to use a fragment? with this?
Optimization has been troubling for weeks on issues.
I have a lot of questions, but I would like to hear good advice on these things.
I would appreciate it if you could explain it slowly and easily.
Thank you very much for reading.
Page has only the contents that change inside according to the date.It`s kind of some diary app. I am worried about whether I need to
ViewPager or not to use ViewPager?
Yes, Viewpager with FragmentStatePagerAdapter is a good choice here, as there may be many dates in your case with its own content.
Check out the below link, it explained very well how any why to use viewpager with tabLayout.
https://guides.codepath.com/android/google-play-style-tabs-using-tablayout
And when I scroll horizontally across the screen, I want to see the
pages change with swipe-animation. Do I have to use viewPager?
For animation between the page swipes, you can use pageTransformer.
Checkout this
https://developer.android.com/training/animation/screen-slide.html
and
https://medium.com/#BashaChris/the-android-viewpager-has-become-a-fairly-popular-component-among-android-apps-its-simple-6bca403b16d4

Alternative to FragmentStatePagerAdapter [duplicate]

I want to find a replacement to the FragmentStatePagerAdapter + PagerFragment as we all know the FragmentStatePagerAdapter is still broken up to this day. There have been a bunch of attempts on github and by myself to make something that mimics the functionality of the FragmentStatePagerAdapter, except all of them seem to have extremely complicated logic with bugs that seem impossible to debug, e.g. https://gist.github.com/ypresto/8c13cb88a0973d071a64.
The core functionality of my application needs to be able to display fragments/views dynamically, e.g. a photo carousel with interleaving ads as the user swipes from left to right and vice versa. And we can dynamically remove or add or manage stuff from/to the adapter.
I've been thinking of potentially making a horizontal recycler view with the view taking up the full screen, and having a bunch of listeners that make the view "center" as the user swipes so that it has a view pager feel to it. But I'm not 100% convinced that this is the best solution to solving this issue. I was wondering if anyone has ever come across issues with FragmentStatePagerAdapter, and has found a good solution to workaround.
Thanks for the help!

ViewPager/ScrollView with multiple view/fragments of different sizes

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.

What's the difference between HorizontalScrollView & ViewPager?

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.

"The type Gallery is deprecated", Whats the best alternative?

I was really surprised that such a Widget gets deprecated.
I want a simple gallery that scrolls left and right, shows a picture on the whole Activity screen, and most important is that you cant swipe more than 1 image in any direction, even if the scroll speed is fast it changes to the next image.
So which Widget should I use? Or should I use a simple ImageView and handle all the swipes and add an animation?
It states in the docs:
This widget is no longer supported. Other horizontally scrolling widgets include HorizontalScrollView and ViewPager from the support library.
HorizontalScrollView will be closer to what you are looking for I think.
I suspect that Gallery was deprecated because it did not properly use convertView with its adapter. Which meant that it had to create a new view for every item which was a drain on performance.
Another option you have is to use the 3rd party created EcoGallery which Joseph Earl created to overcome the issue, this version does recycle its views properly. Unfortunately that pastebin link is the only reference to it I can find online now.

Categories

Resources