2015-08-20 12 views
6

Ich entwickle eine Android App mit einer Aktivität und zwei Arten von Fragmenten.WebView mit einer reduzierbaren Symbolleiste? (Material Design)

Typ 1: ein Fragment mit einer reduzierbaren Symbolleiste und einem RecyclerView als Inhalt. (Es klappt). Layout:

<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/header" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/indicaciones" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" /> 


      <android.support.v7.widget.Toolbar 
       android:id="@+id/anim_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

      </android.support.v7.widget.Toolbar> 

     </android.support.design.widget.CollapsingToolbarLayout> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/scrollableview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" 
     android:clickable="true" 
     android:src="@android:drawable/ic_menu_add" 
     android:visibility="gone" 
     app:layout_anchor="@+id/appbar" 
     app:layout_anchorGravity="bottom|right|end" /> 


</android.support.design.widget.CoordinatorLayout> 

Typ 2: ein Fragment mit einem zusammenklappbaren Werkzeugleiste und einem WebView als Inhalt. (Hier ist das Problem). Ich habe versucht, zu ändern RecyclerView von „WebView“ und es sieht wie folgt aus:

<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/header" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/indicaciones" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" /> 


      <android.support.v7.widget.Toolbar 
       android:id="@+id/anim_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

      </android.support.v7.widget.Toolbar> 

     </android.support.design.widget.CollapsingToolbarLayout> 

    </android.support.design.widget.AppBarLayout> 

    <WebView 
     android:id="@+id/scrollableview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" 
     android:clickable="true" 
     android:src="@android:drawable/ic_menu_add" 
     android:visibility="gone" 
     app:layout_anchor="@+id/appbar" 
     app:layout_anchorGravity="bottom|right|end" /> 


</android.support.design.widget.CoordinatorLayout> 

Das Problem ist, dass die WebView nicht angezeigt. Irgendwelche Vorschläge? Irgendeine Idee, dies zu erreichen? Mache ich es ok?

Vielen Dank im Voraus.

EDIT:

ich die webView auf diese Weise laden:

String template = ... (a xml string, well formed). 
webView.getSettings().setJavaScriptEnabled(true); 
     webView.getSettings().setBuiltInZoomControls(true); 
     webView.getSettings().setDisplayZoomControls(false); 
     webView.loadDataWithBaseURL("file:///android_asset/", template, "text/html", "UTF-8", ""); 
     webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
     webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 
     webView.getSettings().setSupportZoom(true); 
     webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); 

ich auch schon versucht, diese haben:

WebSettings ws = webView.getSettings(); 
    ws.setJavaScriptEnabled(true); 
    webView.loadUrl("http://www.google.com"); 

    webView.setWebViewClient(new WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 
    }); 

Antwort

10

Setzen Sie Ihre Webview in NestedScrollView und setzen android: isScrollContainer: falsch

So es sollte

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <WebView 
     android:id="@+id/scrollableview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:isScrollContainer="false"/> 

</android.support.v4.widget.NestedScrollView> 

Statt Ihre WebView

+0

noch sein Wesen nicht sichtbar ist, werde ich bearbeiten meine Frage, Ihnen zu zeigen, wie ich die webView laden. Danke für Ihre Hilfe. – Borja

+3

NestedScrollView funktioniert, keine Notwendigkeit oder android: isScrollContainer: "false". – Codeversed

+1

https://android-arsenal.com/details/3/4778 –