I have a WebView which displays an HTML file and I would like to add an option to be able to scroll down automatically when a button is clicked with a given speed. How should I approach on doing this?
You can calculate the speed of button clicks by taking difference in unix timestamp between clicks and then you can impliment something like
private Runnable mScrollDown = new Runnable()
{
public void run()
{
WebView webview = (WebView)findViewById(R.id.web_url);
webview.scrollBy(0, scrollSpeed);
mHandler.postDelayed(this, 200);
}
};
I got the answer from link given below. Check it for details.
Auto-scrolling a WebView with handlers
You just need an HTML button which performs a JavaScript call.
Something like:
$('a[href=#bottom]').click(function(){
$('html, body').animate({scrollTop:0}, 'slow');
});
Inspired by: Slow down scroll to top event by jQuery animate
Related
I need to make a credits screen in my application. It would be vertically scrolling lines. It is html page with images so I can only use webview. Scrolling is to be performed automatically and no user interaction is allowed. Just like movie/serials credits that goes from bottom to top. I have html page added in assets folder.
How to implement this animation?
Since you are using a webview, you can actually use jQuery to accomplish this.
$('a[href=#bottom]').click(function(){
$('html, body').animate({scrollTop:0}, 'slow');
});
Slow down scroll to top event by jQuery animate
Or you could use a handler
private Runnable mScrollDown = new Runnable()
{
public void run()
{
WebView webview = (WebView)findViewById(R.id.web_url);
webview.scrollBy(0, scrollSpeed);
mHandler.postDelayed(this, 200);
}
};
I have lots of contents on one page so i am using scrollview. I have one scan button at the bottom of the page, which i need to click many times to scan lots of barcodes. when i click on scan button, i am opening "BarcodeScanner" application that will sacn the barcode and returns the result to my application. so when i come back to my application, again i need to scroll the entire page to click the scan button which is at the bottom side. So is there any way to initialize the scroll at the bottom of the page? Please help
Thanks in advance
How do you think that you can initialise the scroll view.!! If you have lots of contents in a page you have to use scroll view for seeing all the contents. ! Try this, put your scroll view xml code in to botom of the xml code. and check.!!
Say your ScrollView id is scrollId, the code will lokk like this
scrollView = (ScrollView) findViewById (R.id.scrollId);
scrollView.post(new Runnable() {
#Override
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
Try this
s.post(new Runnable() {
public void run() {
s.scrollTo(0, mScrollView.getBottom());
// or this
//s.fullScroll(s.FOCUS_DOWN);
}
});
button.performClick();
For software demonstration purposes, I want to show the user interface updating after each button performClick(). For example, if the Activity was a calculator I can currently simulate the pressing of buttons [1], [2] and [3] using
btn1.performClick();
btn2.performClick();
btn3.performClick();
However, these updates to the EditText too quickly with no visible pause, i.e. it appears "123" are written to the screen simultaneously. What I want is:-
btn1.performClick() updates UI so people can physically see only button press updated to the EditText before the next button does. Similarly with btn2.performClick() and then btn3.performClick().
You may want to use a library like Robotium, and use Solo.waitForText Method to do what you want.
The problem is that we can not determine in advance the time that it will take to display the text, as it depends on the content of your onClick method.
It's why Robotium may be useful for what you want.
You can either use
Thread.sleep(delay);
or use
handler.postDelayed(Runnable,delay);
Use handler for btn2.performClick() and btn3.performClick() like...
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
// do something after 100ms
btn2.performClick();
}
}, 100);
here's what I'm trying to achieve: I assemble a local html page with some tags and internet resources in it, and then load the html page webpage with WebView, and there's a "View More" button at the end of the page, when somebody clicks the button, I'll re-assemble the html page(with old data and new data, like refreshing twitter to load more twits) and have the WebView load it again. But as the user has scrolled to certain location when he clicks the button so I'd like to let the WebView to scroll to the very point where the user was before he clicks the button.
And here's what do by now, I create a WebViewClient and implements:
public void onPageFinished(WebView view, String url) {
view.scrollTo(last_X, last_Y);
}
It does not work as I expect it to, I have 2 concerns, guys please help me out:
1. this callback function does not work all the time. for most of the time, it works, but sometimes, for unknown reasons, it just does not work.
2. even if it works, it's not exactly what I want. as I mentioned, the html page contains some internet resources like
<a href='whateversite/whateverimage'><img src='whateversite/whateverimage'></img></a>
So the scrollTo function only got called when all images are loaded, it takes too much time and it's unnecessary, is there any way to start scrolling when the page is loaded but before all other resources got loaded? Per say, as long as webview.getContentHeight() > 0, it's OK to scroll.
Apologize for my poor english that I'll have to use load of words to try to make myself clear.
Guys, please halp~
Do something like this :
view.post(new Runnable() {
public void run() {
view.scrollTo(last_X, last_Y);
}
});
Is there some way to set an onClickListener for a webview? I've seen code here to intercept url clicks but I would just like to intercept anytime a user clicks the area the webview's on or swipes across it with their finger. I load html directly into the webview (as opposed to giving it a url) for formatting reasons and I'd really like to be able to tell any time the user clicks anywhere on the screen. I had been using a textview and that works fine, but is it doable with a webview?
Have you tried instead of an onClick, an onLongClick listener?
Taken from my recent project:
printMessageTextView.setOnLongClickListener(new OnLongClickListener() {
int active = 0;
#Override
public boolean onLongClick(View v) {
In this case, the int active = 0; is probably not needed. But should be able to listen for you.