Reputation: 11
I have the following code to display a web page. Everything in this layout was working fine but when i added the web view, the web view isn't working. Please let me know how to fix this. I also suspect that the problem is with the nesting of the web view because I tried to open the same web page using another sample app with a web view without any parent views and it worked.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme"
android:titleTextAppearance="@style/Toolbar.TitleText"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp">
<include
android:id="@+id/user_profile_toolbar"
layout="@layout/user_name"
android:layout_width="match_parent"
android:layout_height="72dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.example.personal.newsfeeder.DetailActivity">
<WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</WebView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Upvotes: 0
Views: 602
Reputation: 9117
Webview
inside ScrollView
is trouble some layout.. you can try android:fillViewport="true"
for NestedScrollView
and layout_height="match_parent"
for WebView
.. remove the unnecessary LinearLayout
inside nestedscroll.. just use WebView
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fillViewport="true">
Try also webview height change to static height.. if you want.. it might work also
make sure you use latest android support design library
Upvotes: 1
Reputation: 11
Thank you everyone for trying to help. I figured out the solution. It was not in the layout file at all. The link to load the web page in the line myWebView.loadUrl("xyz")
was just empty string and I just forgot to initialize that string correctly.
But I don't think there is any issue here in my layout by using WebView inside the NestedScrollView. It works smoothly for me.
But please do let me know if its not a good practice to use WebView inside the NestedScrollView.
Upvotes: 0