This is my first question on StackOverflow, but I've learned a lot here already.
Now I have a problem, which I couldn't solve.
I have a horizontal scroll view with some buttons on it (let's say 20 buttons). When I scroll and stop the scrollview, it needs some time to accept clicks by buttons. I mean - onClick method desn't fire.
It could be observed best when scrolling is fast, and stops rapidly because of coming to the end of scrollbar.
Then it takes 2 clicks to get the button action.
I think this is some focus problem, or it's about of scrollview events implementation on scrolling.
As a ScrollView moves along, it unloads out-of-focus things and loads coming-into-focus things. This may be why the button's click takes a bit to register.
A project of mine learned this the hard way after we had already implemented everything in it. It worked great before the ScrollView had large amounts of content. Then once it did, it was super laggy and that's when we learned this.
Related
I'm new to Android, and decided to practise with ExpandableListView.
The application is very basic ExpandableListView: taken from here:
https://startandroid.ru/ru/uroki/vse-uroki-spiskom/86-urok-45-spisok-derevo-expandablelistview.html
I try to improve the animation of expanding and right after
elvMain.setAdapter(adapter); (the last line of code) I applied the following code:
LayoutTransition layoutTransition = elvMain.getLayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
The parent expands very nice and smooth, but after this first click, the whole view is not clickable, but... if I swipe just a bit on the buttons (in any direction), the parents and children respond to the swipe: the parents expand ok, or they become clickable after this swipe, but, again, only once.
What may hinder them from being clickable, and how this couold be worked around? Please share your experience or expertise. Thank you so much!
I have thoroughly investigated the problem, and tried a lot of things, but could not figure it out...
I have seen an app which has different type of scrolling. I hope images attached will be able to explain it. Here the list when scrolled up, moves up by taking DownloadAll, Playall button up too. Later on DownloadAll and PlayAll button stops going up and only the list scrolls up.
I don't know what this is called as. I tried searching, but could not find anything similar.
How can I achieve this type of scrolling?
Take a look at "Libraries for developers" it has a section of listview where you can find different styles of listviews (plus scrolling animations such as sticky, animated scrollview, flabby etc...)
I have linear layout inside a scrollview, and i would like to keep those views which are not visible(which are inside the linear layout) from being created until they are either visible or near to being visible. Like adjacent to one that is visible. I don't know if for example if turning off visibility will keep the View from being created(in terms of resources), or if gone could be used.
Update: The reason I am asking this question is because scrolling is taking a heck of a long time when there are say 30 view elements in the linear layout. These are not large view elements either, about what you would find for a record in a listview. I should add that the whole scrollview is inside a fragment.
Thanks
You have a LinearLayout(vertical) with 30 children. If you scroll to the bottom, which views would then be "created"?
If only the visible(or near visible) ones, then you can't measure how far down in the scroll they will be any more.
If at that point you're just saying you should create them when they first appear, and stay around afterward, that could work. However, once you scroll around some, you'll still have a bunch of views, and the same problem you have now.
Scrollviews exist and I happen to be using one.
True, but that doesn't necessarily means it's the best tool for the job. I tried something similar with my first Android project. I didn't know much about ListViews, and ended up rolling my own adapter that sounds eerily similar to what you're doing.
Long story short, the performance was bad. It did work, but once I(finally) switched to a ListView, the difference was nothing short of amazing. I'm just trying to keep others from going down that road. It was days of wasted time trying to get it "just right".
I have implemented a ViewPager in my app, and aside from the swipe paging, I have buttons for "Next" and "Back", with a simple onClick method with the only line being a setCurrentItem for the ViewPager.
While the paging animation is completely smooth during swiping, it is more or less instantaneous (just flips instead of scrolling) when I click Next or Back. There is no visible "scrolling" motion, or sometimes barely visible, however not even close to smooth. It does not hurt the usability of the app in any way, since the transition still happens immediately, but visually it looks a lot less appealing, and the user experience suffers.
Now, I suspect it has something to do with the app drawing the next View and therefore "skipping" the animation. My instantiateItem uses LayoutInflater and a simple switch statement to inflate each view (4 pages at most), and I am loading custom ListViews inside each case in the switch statement. The custom ListViews are at most 3 items long, with a TextView and an ImageView in each row (ImageView resource is 5kb in size). To me it seems this amount of objects should not be reason enough to slow down the paging animation.
Aside from that, I also have a custom background assigned to my app in styles.xml, and this is the background used through every activity (160kb in size).
Those are the only things that I think could be slowing down the app, since the onClick method contains only one line (setCurrentItem), so nothing aside from going to the next view is happening in the app, and the instantiateItem is the simplest implementation of the method possible that I know of.
Things I've tried:
Setting the ViewPager's setOffScreenPageLimit to 4, which I thought would pre-load the views and eliminate any loading in between paging, but in the end setting it to 0 seemed to make the thing slightly more likely to show at least a frame of animation
Optimizing the custom ListViews by using convertView to reuse old views, while it did result in more of the animation being shown, it still wasn't completely smooth, varying from "almost perfect animation" to "instant flip"
Removing the custom background, which together with the above two fixes lead to an almost good enough solution, but still resulted in flips every few steps.
The tinkering described above leads me to believe it has something to do with the views being loaded, but I've not found a good solution for pre-loading these to the desirable effect.
Knowing my newbie programming skills, I know there is a sure fire way to solve this without resorting to gimping the design of the app itself, but reading through the documentation, Stack Overflow questions, Googling for advice, I've just ran out of places to look to.
To sum up this probably too verbally descriptive post my main questions are:
Is there a way to ensure the animation of the ViewPager is executed smoothly? A separate thread perhaps? As I understand though, UI stuff should only be on the main thread, where it already is, and nothing else aside from the view loading is executed anywhere in the code when paging.
Should I be using a different way to load the pages? Would Fragments help?
Thank you for any advice.
ps. The lack of code is due to the methods in question being the most basic implementations possible, but I will provide the code if necessary.
I have a ViewFlipper with multiple views added dynamically. I override onTouchEvent (and onInterceptTouchEvent) in order to get the down, move and up events on the views, so I know when to animate left and right.
Now everything works fine, except that there is a small flicker (one of the other views is displayed on top for a split second) at the beginning of the swipe. This only happens after the first swipe is done.
I looked at the source code for the Home screen app on Android, which helped a lot, but they don't use the ViewFlipper, so it's a little different.
Did anyone encounter the same problem?
Thanks!