WebView with scroll list at the top
I need to create an application that has a very similar interface to Chrome. In other words, I need to create a WebView and a top bar that:
- disappears when the user scrolls down the page (the panel scrolls off the page),
- appears when the user scrolls up the page,
- when the user scrolls down the page so that only half of the panel is shown and then just disappears.
The important (possibly) thing is that I cannot change the displayed HTML. I already realized that I have to create my own class that extends the WebView and overrides onScrollChanged()
in it. Here's what I managed to write:
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (flag) {
flag = false;
return;
}
View bar = getRootView().findViewById(R.id.bar);
if (bar != null) {
int difft = oldt - t;
float oldY = bar.getTranslationY();
float newY = Math.max(-bar.getHeight(), Math.min(0, bar.getTranslationY() + difft));
bar.setTranslationY(newY);
View layout = getRootView().findViewById(R.id.layout);
layout.setTranslationY(bar.getHeight() + newY);
flag = true;
if ((int) (newY - oldY) != 0) {
scrollBy(0, difft);
}
}
}
(layout is the container the WebView is in and bar is the top bar. I have placed both views in a RelativeLayout)
And well, it almost works. Almost because it causes some flickering and I don't know what the problem is. Also, it doesn't solve problem # 3 (and I really don't know how to solve it in the simplest way, with some kind of animation, for example in Chrome - smooth movement up).
source to share
No one has answered this question yet
Check out similar questions: