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 !
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"/>
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.
Related
I have an application which shows a multiple webView inside a listView. My problem is when I try to scroll the webView up and down, the webView does not respond to my finger except if I used 3 fingers only. And when it responds it's hardly moving up and down. I figured out that the problem is the listview is banning the webView from scrolling. I have tried using:
listView.setEnabled(false);
But it didn't work for me. could anyone show me how to solve this problem?
This is how I added the webView layout inside a listView.
ArrayList<DefaultCards> cardsList = new ArrayList<>();
cardsList.add(new DefaultCards("Hello Google","https://www.google.com", new WebViewClient()));
CardsAdapter cardsAdapter = new CardsAdapter(this, cardsList);
ListView listView = findViewById(R.id.cards_listview);
listView.setAdapter(cardsAdapter);
listView.setEnabled(false);
And this is the layout that will show the listView:
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cards_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
And finally, this is the layout that will be inserted into a listView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="#color/colorBackground"
android:padding="5dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="50dp"/>
</android.support.v7.widget.CardView>
Take this with a grain of salt but you might want to try using a recycler view for your list holder and a nested scroll view for your webview container.
Also, if the content of the webview is large enough to scroll you may need to add the isScrollContainer="true" attribute to your webview's xml.
Again, this is just a wild guess. Hope it helps!
The listview is intercepting the scrolling. You can prevent this by creating a NestedScrollingWebView that implements NestedScrollingChild, NestedScrollingParent.
There are many code samples if you search for Nested Scrolling Webview.
Use that instead of a regular Webview.
I want to create news like activity that has title and date and some share and favorite buttons in the beginning at the top, the article text (and maybe some images and headers titles) is in html that I get from server, and at the end a list of related news!
I have to use WebView for the article html, but since I need the header and the main webview to scroll together, I may have to use them in the in wraping ScrollView, which, apparently is not the best option!
I have red these:
webview in scrollview and
Disable scrolling in webview
but I want to know what is the best way to implement this as of 2015! that can work with android 4.01+
Well, as it turns out, best way to do yet is to just put them in a scrollView !
It worked on my Samsung android 4.4, but I don't know about the rest !
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/news_activity_title_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//Some Widgets Here for header
</RelativeLayout>
<WebView
android:layout_below="#+id/news_activity_title_lay"
android:id="#+id/news_activity_web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
</WebView>
<LinearLayout
android:id="#+id/news_activity_related_base_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/news_activity_web_view">
//Some Widgets Here foe footer
</LinearLayout>
</RelativeLayout>
funny thing, though is Android Studio is saying I should not do this ! :/
xml file for my About Screen .. i've done this because my app supports API 9 which does not support DialogFragments, so i am using another class to display another screen instead .. the problem is, i cant seem to scroll through the whole page, my .xml contains nested LinearLayout that also has TextViews .. i tried adding android:scrollbars="vertical" to the main <LinearLayout> but nothing happens .. i hope someone can help me out, thanks :)
My XML file Pasted here.
ScrollView can only support a single child. So enclose your nested LinearLayouts inside a single LinearLayout and further enclose that parent LinearLayout inside a ScrollView. I have done this for you. You can use this http://pastie.org/9528662
Wrap your root LinearLayout with ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--your nested linearlayouts here-->
</LinearLayout>
</ScrollView>
I need a vertical scrollview similar as present in below image.
But I have Got scrollview as present in below picture
My code is
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:scrollbarThumbVertical="#drawable/scroll_bar_thumb"
android:scrollbarTrackVertical="#drawable/scroll_bar_track">
My problem is scroll_bar_thumb goes inside the scroll_bar_track. Give some solutions.
Thanks in advance.
Try looking here
Custom scrollbar Android
and maybe there
https://github.com/rno/Android-ScrollBarPanel
I have a WebView inside the ScrollView.
The content of WebView dyanamically changes when it displays different html page.
I have the following issue:
For example I have A.html, and B.html. The content of B.html is larger than A.html, so the page is longer.
When WebView load B.html, the ScrollView stretches its size to enable itself scroll for B.html, then if I go back to A.html, ScrollView doesn't resize itself. (The scroll area is exceed the content of A.html)
What I want to have, is dynamic change the scroll area of scroll view to fit the webview's content.
Try using android:fillViewport in scroll view..!!
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
After Orientation screen will resize, it works but bad in performance, not a very good solution
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_SENSOR );
This helped me:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
That's not good idea to place WebView inside of ScrollView. WebView is smart enough to show scrollbars by itself.
Don't put a WebView inside of a ScrollView.