9

これは私のレイアウトです。 google.comを読み込むと、ウェブビューの高さは無期限に増え続けます。 webviewのonSizeChange関数が呼び出され続けると、webviewが無限に拡大し続けるのがわかります。私は22.2.1と23.1.0のデザインライブラリとappcompatライブラリを試しましたが、何の効果もありませんでした。nestedScrollView内でWebViewの高さが無期限に増加する

: - |一つの文章で

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

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

    <com.example.ajay.scrollabletoolbar.MyWebView 
     android:id="@+id/webview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true"/> 
</android.support.v4.widget.NestedScrollView> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbarlayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/restricted_browser_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?actionBarSize" 
     android:background="@color/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#FFFFFF" 
      android:descendantFocusability="beforeDescendants" 
      android:focusableInTouchMode="true"> 

      <EditText 
       android:id="@+id/current_url" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_centerVertical="true" 
       android:backgroundTint="@android:color/darker_gray" 
       android:dropDownAnchor="@+id/restricted_browser_toolbar" 
       android:hint="hint hint" 
       android:imeOptions="actionGo|flagNoExtractUi" 
       android:inputType="textNoSuggestions|textUri" 
       android:paddingBottom="8dp" 
       android:paddingEnd="8dp" 
       android:paddingStart="8dp" 
       android:singleLine="true"/> 

      <ImageView 
       android:id="@+id/clear_url_text" 
       android:layout_width="48dp" 
       android:layout_height="48dp" 
       android:layout_alignRight="@+id/current_url" 
       android:layout_centerVertical="true" 
       android:layout_marginRight="8dp" 
       android:src="@android:drawable/ic_menu_close_clear_cancel" 
       android:visibility="gone"/> 
     </RelativeLayout> 
    </android.support.v7.widget.Toolbar> 
</android.support.design.widget.AppBarLayout> 

+0

固定サイズに設定する – Nanoc

+1

固定サイズを使用することはできません。私はすべての携帯電話とタブレットでフルビューを取るためにwebviewを望んでいます。 – onusopus

+0

もちろん、ウィンドウサイズをwebviewに設定するのと同じくらい簡単に、なぜあなたは傾けることができますか? – Nanoc

答えて

5

あなただけNestedScrollViewの内側にあなたのWebViewを置くことはできません。これは意図したとおりに動作しています。

あなたがNestedScrollView(またはScrollView)内WebViewを置く場合は、あなたのWebViewView.MeasureSpec.UNSPECIFIED要件とその寸法を測定します。あなたがWebViewの高さのためにMATCH_PARENTまたは100dpのような固定サイズさえ設定しても関係ありません。 NestedScrollViewは、子どもたちにView.MeasureSpec.UNSPECIFIEDの要件で自分自身を測定させます。すべてNestedScrollViewmeasureChild()メソッドで発生します。そのラベルが示すとおり、それはそれは望んでいるものは何でもサイズにすることができ、

@Override 
protected void measureChild(View child, int parentWidthMeasureSpec, int parentHeightMeasureSpec) { 
    ViewGroup.LayoutParams lp = child.getLayoutParams(); 
    int childWidthMeasureSpec; 
    int childHeightMeasureSpec; 
    childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, getPaddingLeft() 
      + getPaddingRight(), lp.width); 
    childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); 
    child.measure(childWidthMeasureSpec, childHeightMeasureSpec); 
} 

そしてMeasureSpec.UNSPECIFIED手段:それは以下のようになります。私は"Writing Custom Views for Android" session at Google I/O 2013からのこのスライドはあなたがそれを理解するのに役立つと思います。

enter image description here

実はこれは、デスクトップでは、あなたはそれようのページの高さに、ブラウザウィンドウのサイズを変更するかのようにこれがあるthis threadで議論された問題であり、そしてthis Google engineerによると、

垂直方向にスクロールできません。スクロールはwebview自体ではなく、NestedScrollViewで行われています。したがって、ページ内のjsの結果はスクロールイベントを見るので、ページの最後までスクロールしてより多くのコンテンツをロードしたことはわかりません。

だから、一番下の行は、NestedScrollView内でごWebViewを入れないでください、です。 WebViewはウェブページ自体をスクロールさせるべきです。ハッピーコーディング! :)

0

私はこの質問を早く締めてくれないことをお詫びします。私たちは、nestedScrollViewの中にwebviewを置くことはできません。しかし、NSVの性質は、子どもを完全な高さに拡張するので、ツールバーで折り畳み/スクロール可能なツールバーなどを使用して期待どおりに機能するようになります。したがって、webviewが追加されると、Webviewは無期限に、期待どおりに動作しません。これは参考にすることができます:code.google.com/p/android/issues/detail?id=198965

関連する問題