7

I have a Webview loading static html content in my app.

the problem is, when I click on a link or an embed content (tweet, youtube video), the webview is scrolling back to the top.

It looks like a JS problem as mentioned here

I tried to use a NestedScrollView or some tricks with params like

android:focusableInTouchMode="true"

in a LinearLayout parent but nothing works

here's my xml :

  <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
      android:id="@+id/article_webview"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>
  </android.support.v4.widget.NestedScrollView>

it will be in a recycler view.

My question is :

is there a way to prevent this behavior in the webview settings or xml ?

Thanks !

Paul Aigueperse
  • 299
  • 3
  • 14

2 Answers2

8

I've been having the same problem. My WebView was inside a RecyclerView too.

When I added android:descendantFocusability="blocksDescendants" on my RecyclerView, the problem does not happen for me anymore.

<androidx.recyclerview.widget.RecyclerView
  android:descendantFocusability="blocksDescendants"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
2

I've been having the same problem. My WebView was inside a LinearLayout.

When I added android:descendantFocusability="blocksDescendants" on my LinearLayout. Issue was fixed with this changes.

Danish Ali
  • 21
  • 1