I've stumbled upon another tricky error...
I'm using basic ViewPager, which consists of several pages, which are basically consisted of HTML, displayed by a WebView.
I use the method:
mWebView.loadDataWithBaseURL(null, html, "text/html", "utf-8", "about:blank")
for showing the contents. HTML is a String variable. Everything work fine, but I would expect all the views to be preloaded (I've set offscreenpage limit of the viewpager and even instantiate item is called right with the right data), but it isn't.
The webview is loaded, but displayed only after the click. It doesn't occur to me first, because I clicked everytime I wanted to show another page, but if you move to quickly, clicks get a bit delayed and no page is displayed. Only after I click again.
Or, if I drag one page and move slightly right, I can see that the another view is not loaded yet... it displays only after one second.
Has anybody encountered something similar?
Any help is appreciated.
I have the same problem and am looking for help, too. It seems that the entire ViewPager doesn't show up until it has focused after the click, but none of the requestFocus() nor requestChildFocus() did work.
One little different thing, the problem only happens to me when the ViewPager is initialized. When I moved to another page, the webview content displayed well.
I have found the solution for this: just simply use the ViewPager.setCurrentItem(position) to display the page that you want as default (normally the first page in my case).
You need to remove setPageTransformer in pager. I have same problem and I fixed it.
Related
I really stuck in a simple operation :-/
I have a number of section to swipe left / right as an Adapter / ViewPager, number of pages are defined dynamically during run-time.
There is button in the page which caption I would like to change during run time.
Of' cause Android is creating several pages in once to cash them and speed up scrolling. This leads to the problem that if I just look for a button using findViewById and change the caption, this change will be applied for the next screen, and not for the current visible one.
I can get the number of currently displayed ViewPager by .getCurrentItem but I cannot understand how I can address the very this button which is currently on screen.
Would be happy for any advice!
p.s. Sorry that I do not attach the code, it's quite long.
Change the text in an OnPageChangeListener with addOnPageChangeListener.
I have an android app with ViewPager from the support library.
Inside fragment's view, I have some Views on top and a WebView with some HTML contents below them.
First page is loaded properly, but when switching between pages, every next page automatically scrolls down to the webview and focuses something in it (image, hyperlink) marking it with a default style (orange color on my phone). This is extremely weird, I don't know where it comes from and I want to get rid of this behavior. Each page should be on its top (scroll position 0) when opened.
It happens with a short latency after loading view (onCreateView), so setting scroll position to 0 in onCreateView did not help.
After sliding to another page, it should look like this:
good version http://imageshack.us/a/img254/4623/shotgood.png
But after approx. a second, it automatically scrolls down, focuses a link and looks like this:
bad version http://imageshack.us/a/img855/1848/shotbad.png
Anyone experienced such issue and knows solution?
Thanks in advance.
EDIT: I have noticed that this issue does not occur while I don't scroll vertically inside any fragment. After I scroll vertically and then slide to another page, it starts to happening on every next page.
After few days of searching, I've finally found solution described here:
Webview inside a View pager in android
point is adding
android:descendantFocusability="blocksDescendants".
to the outer-most linear layout.
I am using a ViewFlipper to toggle between views. I would like to get the same effect as Facebook's or Youtube's settings views, which is to keep a bit of the last view showing to the right. See image below. How can I do this?
Instead of using a ViewFlipper, try a ViewPager. The ViewPager is best, I think, if you want to have different pages and let the user control which one they see. It uses the paging animation by default, and you can specify page width so the user can see parts of the page next to it.
I would like to know how to go about doing this small problem that I am encountering while making a video player app.
On clicking the first control(the rectangular icon) in the above image the following view must be displayed instead of it which I am quite unsure as to how to do it. Here is what it is replaced by
Also please note, by any chance the activity should not be changed. I have been able to design the views individually but having problem changing them at runtime when user clicks. Could someone go about explaining as to how it can be done or provide some suitable links to achieve my goal. Thanks.
For something as simple as this you can just change the visibility of the views.
view.setVisibility(View.INVISIBLE)
Or the more effective:
view.setVisibility(View.GONE)
Do that on the views you want gone, I suggest a wrapper class. It's either this or changing the contentView as describded below.
this.setContentView(R.layout.newLayoutToUse);
However, I have a feeling there is a better way to do what you want. It's overkill to load a complete new layout if you just want to change the image of some buttons or imageviews.
This might be a stupid solution, 'cause i'm terribly tired right now, but why not use the bringToFront() method on the View that you want to display in the front? Display them both in front of each other, maybe in a RelativeLayout, and then swap between them as you wish.
They are small objects, so don't consume memory. I don't see why this shouldn't work.
OR
Place them above one another, so they overlap and then make the above view visible/invisible depending on which one you need to display.
OR
just remembered I read somewhere that you can scroll through a ScrollView automatically from code. So display both Views in a ScrollView in succession and when pressing the button or whatever, you scroll down to make the next menu visible. When pres back, you scroll up to make the previous thing available. Should work, and might also make a nice animation between changing of the menus.
I'm trying to add some arrows to the screen to indicate if there are items available to the left or right so that the user knows to scroll.
Initially I just added these images into the instantiateItem function in the pageradapter. However I want to animate the arrows so that they fade in and out and disappear when the user touches the screen.
I've started to think that I may be best off extending the viewpager class so that it always displays the arrows independently of the adapter. I've looked through the code but can't see a place where I would add the overlay view.
Has anyone got any ideas?
Thanks,
m
As suggested by CommonsWare
You might wish to take a look at github.com/JakeWharton/Android-ViewPagerIndicator and see how Jake did it.
this information lead me to the solution.