質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

2回答

5802閲覧

NestedScrollViewの中にWebViewを使用したとき、モーダルウィンドウがサイトの中央に表示される

ludolf

総合スコア39

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2019/09/11 11:59

編集2019/09/19 05:55

いつもお世話になっております。

早速ですが、Fragmentを使用してWebviewを複数に設置し、スワイプして各サイトを閲覧できるウェブアプリを作成しております。

【問題点】
NestedScrollViewでWebViewを囲ってtoolbarの開閉を行っているのですが、高さがサイト全体の高さになってしまい、モーダルウィンドウの位置がサイトの真ん中に表示されてしまいます、、

色々調べてみると同じ症状っぽいサイトがあったのでそれを参考にやってみたのですが、変わらず、、

下記自分のxmlです。

xml

1<?xml version="1.0" encoding="utf-8"?> 2<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 xmlns:app="http://schemas.android.com/apk/res-auto" 7 tools:context=".ui.main.RedView"> 8 9 <androidx.core.widget.NestedScrollView 10 android:id="@+id/nestedScrollView" 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content"> 13 <ScrollView 14 android:id="@+id/scrollView" 15 android:layout_width="match_parent" 16 android:layout_height="match_parent"> 17 <WebView 18 android:id="@+id/RedWebView" 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 tools:layout_editor_absoluteX="8dp" 22 tools:layout_editor_absoluteY="8dp" 23 android:isScrollContainer="false"/> 24 </ScrollView> 25 </androidx.core.widget.NestedScrollView> 26</FrameLayout>

参考サイト:https://dashimaki-dofu.hatenablog.com/entry/2018/09/05/165601

必要であればFragmentのjavaプログラムも書きます。
【教えてほしいこと】
なぜモーダルを開いたときWebViewの高さではなく、サイトの高さが反映されるのでしょうか?
参考サイトもしくは解決策ご教授願います!

よろしくお願いします!

↓activity_main.xml追記↓

activity_main.xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:id="@+id/drawer_layout" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 android:fitsSystemWindows="true" 9 tools:openDrawer="end"> 10 11 12 13 <androidx.coordinatorlayout.widget.CoordinatorLayout 14 xmlns:android="http://schemas.android.com/apk/res/android" 15 xmlns:app="http://schemas.android.com/apk/res-auto" 16 xmlns:tools="http://schemas.android.com/tools" 17 android:layout_width="match_parent" 18 android:layout_height="match_parent" 19 tools:context=".MainActivity"> 20 21 22 <com.google.android.material.appbar.AppBarLayout 23 android:layout_height="wrap_content" 24 android:layout_width="match_parent" 25 android:theme="@style/AppTheme.AppBarOverlay"> 26 27 <androidx.appcompat.widget.Toolbar 28 android:id="@+id/toolbar" 29 android:layout_width="match_parent" 30 android:layout_height="match_parent" 31 android:background="@color/white" 32 android:paddingTop="15dp" 33 android:paddingBottom="15dp" 34 app:layout_scrollFlags="scroll|enterAlways"> 35 36 37 <androidx.appcompat.widget.AppCompatImageButton 38 android:id="@+id/logo_top" 39 android:layout_width="wrap_content" 40 android:layout_height="wrap_content" 41 android:layout_gravity="center" 42 android:adjustViewBounds="true" 43 android:scaleType="fitCenter"/> 44 45 </androidx.appcompat.widget.Toolbar> 46 47 <com.google.android.material.tabs.TabLayout 48 android:id="@+id/tabs" 49 android:layout_width="match_parent" 50 android:layout_height="35dp" 51 android:background="@color/white" 52 android:paddingTop="0dp" 53 android:paddingBottom="0dp" 54 android:paddingLeft="0dp" 55 android:paddingRight="0dp" 56 android:state_selected="true" 57 app:tabBackground="@drawable/tab_color_selector" 58 app:tabGravity="fill" 59 app:tabMaxWidth="0dp" 60 app:tabMode="fixed" 61 app:tabTextAppearance="@style/TabText" /> 62 63 64 </com.google.android.material.appbar.AppBarLayout> 65 66 <androidx.viewpager.widget.ViewPager 67 android:id="@+id/view_pager" 68 android:layout_width="match_parent" 69 android:layout_height="match_parent" 70 android:focusable = "true" 71 app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 72 73</androidx.coordinatorlayout.widget.CoordinatorLayout> 74 <com.google.android.material.navigation.NavigationView 75 android:id="@+id/nav_view" 76 android:layout_width="240dp" 77 android:layout_height="match_parent" 78 android:layout_gravity="end" 79 android:fitsSystemWindows="true" 80 app:menu="@menu/activity_main_drawer" /> 81</androidx.drawerlayout.widget.DrawerLayout> 82 83

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kakajika

2019/09/18 02:48

NestedScrollViewで囲っているのは何のためでしょうか?
ludolf

2019/09/19 06:01

いつもお世話になっております! NestedScrollViewはactivity_main.xmlにあるtoolbarのlayout_scrollFlags開閉の判定のために設置しています。 NestedScrollViewとScrollViewを取って、WebViewのみ書いてしまえば思うような動きになるのですが、それだとtoolbarの開閉ができなくなってしまいます、、 activity_main.xml追記しておきました! 何卒ご回答おねがいします!
guest

回答2

0

1万文字を超えていたため変更したコードのみ下記記入しますね。
(変更箇所は合計8点です)

① import androidx.core.view.NestedScrollingChild; ② public class NestedWebView extends WebView implements NestedScrollingChild { ③ public boolean startNestedScroll(int axes, int type) { return mChildHelper.startNestedScroll(axes, type); } ④ public void stopNestedScroll(int type) { mChildHelper.stopNestedScroll(type); } ⑤ public boolean hasNestedScrollingParent(int type) { return mChildHelper.hasNestedScrollingParent(type); } ⑥ public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow, int type) { return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow, type); } ⑦ public void dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable int[] offsetInWindow, int type, @NonNull int[] consumed) { mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow, type); } ⑧ public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow, int type) { return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type); }

投稿2019/09/26 09:45

ludolf

総合スコア39

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

WebViewのlayout_heightがwrap_contentなので、高さがコンテンツの高さになってしまっていますね。WebViewをNested Scrollに対応させたいなら、WebView自身にNestedScrollingChildを実装する方法があり、「NestedWebView」等で検索すると実装例がいくつか転がっています。こことか

これらのNestedWebViewを使う場合はNestedScrollViewおよびScrollViewは不要になるので、FrameLayoutの下に直接配置してください。

補足

最近AndroidXをアップデートしたところうまく動かなくなっているものが多かったので、その場合は最新のインターフェースである NestedScrollingChild3 を実装しているこちらのNestedWebViewを使ってみてください。

投稿2019/09/19 12:26

kakajika

総合スコア3131

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ludolf

2019/09/20 01:33

ご回答ありがとうございます! 現在AndroidStudioを使用できない状態で確認が取れていませんが、WebView自体にNestedScrollingChildを実装する方法だったら多分動くかと思います! やってみた際に実際に動いたらベストアンサーにしたいかと思います! 出来なかったらまた質問するかと思います、、 すみませんが、しばらくお待ちください!
ludolf

2019/09/26 09:36

今kakajikaさんが送ってくださった参考サイトをそのままコピぺしたところエラーが何件かありました。 OverrideしないメソッドをOverrideしていたり、NestedScrollingChild3が使用できませんでした、、 そこで自分の方でちゃちゃっとエラーがあるところだけ変えてみたら上手く動きました! ほんとに初心者が思い付きで変えたので当たっているか正直怖いのが本音ですが、思うような動きができたためベストアンサーさせていただきます。 前回から本当にありがとうございます! あと自分が修正したコード載せておきます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問