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

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

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

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

Android

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

Android Studio

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

Q&A

解決済

2回答

2659閲覧

Android studio xmlのlayout_heightのmatch_parentについて

ludolf

総合スコア39

Java

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

Android

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

Android Studio

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

0グッド

0クリップ

投稿2019/10/25 05:22

編集2019/10/29 02:52

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

現在WebViewの表示で躓いており助言をお願いしたく、本投稿をしております。
イメージ説明
上記の画像が例になるのですが、空白の部分にWebViewが設置されているアプリを作成しているのですが下のナビゲーションバーにWebViewが食い込んでWebView全体が表示されていない状態にあります。
理由は自分でも理解していてWebViewにmatch_parentを設定しているので下部にあるナビゲーションを抜いた高さになっています。
【質問】
ナビゲーションバーの高さを引いた高さをWebViewに実装できますでしょうか?
下記自分のwebviewとナビゲーションバーが書いてあるコードです。

xml

1 2<androidx.coordinatorlayout.widget.CoordinatorLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 tools:context=".MainActivity"> 9 10 <com.google.android.material.appbar.AppBarLayout 11 android:layout_height="wrap_content" 12 android:layout_width="match_parent" 13 android:theme="@style/AppTheme.AppBarOverlay"> 14 15 <androidx.appcompat.widget.Toolbar 16 android:id="@+id/toolbar" 17 android:layout_width="match_parent" 18 android:layout_height="match_parent" 19 android:background="@color/white" 20 android:paddingTop="8dp" 21 android:paddingBottom="8dp" 22 app:layout_scrollFlags="scroll|snap"> 23 24 25 <androidx.appcompat.widget.AppCompatImageButton 26 android:id="@+id/logo_top" 27 android:layout_width="wrap_content" 28 android:layout_height="wrap_content" 29 android:layout_gravity="center" 30 android:adjustViewBounds="true" 31 android:scaleType="fitCenter" /> 32 33 </androidx.appcompat.widget.Toolbar> 34 35 <com.google.android.material.tabs.TabLayout 36 android:id="@+id/tabs" 37 android:layout_width="match_parent" 38 android:layout_height="35dp" 39 android:background="@color/white" 40 android:paddingTop="0dp" 41 android:paddingBottom="0dp" 42 android:paddingLeft="0dp" 43 android:paddingRight="0dp" 44 android:state_selected="true" 45 app:tabBackground="@drawable/tab_color_selector" 46 app:tabGravity="fill" 47 app:tabMaxWidth="0dp" 48 app:tabMode="fixed" 49 app:tabTextAppearance="@style/TabText" /> 50 51 52 </com.google.android.material.appbar.AppBarLayout> 53 54 //下記問題のWebViewとナビゲーションバーです。 55 56 <androidx.viewpager.widget.ViewPager 57 android:id="@+id/view_pager" 58 android:layout_width="match_parent" 59 android:layout_height="match_parent" 60 android:focusable = "true" 61 app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 62 63 64 <com.google.android.material.bottomnavigation.BottomNavigationView 65 android:id="@+id/bottom_navigation" 66 android:layout_width="match_parent" 67 android:layout_height="wrap_content" 68 android:background="@color/white" 69 app:layout_anchor="@+id/view_pager" 70 app:layout_anchorGravity="bottom" 71 app:itemHorizontalTranslationEnabled="false" 72 app:labelVisibilityMode="labeled" 73 app:layout_constraintBottom_toBottomOf="parent" 74 app:layout_constraintLeft_toLeftOf="parent" 75 app:layout_constraintRight_toRightOf="parent" 76 app:menu="@menu/bottom_navigation_menu" /> 77 78   //ここまで 79 80 </androidx.coordinatorlayout.widget.CoordinatorLayout>

viewPagerからWebViewの表示している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.ItemOneWebView"> 8 <androidx.core.widget.NestedScrollView 9 android:layout_width="match_parent" 10 android:layout_height="match_parent"> 11 <com.itemonewebview.NestedWebView 12 android:id="@+id/ItemOneWebView" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:isScrollContainer="false"/> 16 </androidx.core.widget.NestedScrollView> 17</FrameLayout>

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2019/10/25 10:22

WebViewなんてどこにもないですけど…
ludolf

2019/10/29 02:46

質問ありがとうございます! すみません説明不足でした、、 Fragmentを用いてスワイプすると上のタブメニューが移動し、違うドメインのURLが開くといった仕様にしています。 なので「ITEM ONE」にいるときは「https://hoge.com/ITEM ONE/」のURLを見ていて、スワイプもしくは「ITEM TWO」をタップすると「https://hoge.com/ITEM TWO/」のURLが開くようにしております。 ViewPagerは複数のWebViewを管理する用に使っています。 ご回答お待ちしております!
退会済みユーザー

退会済みユーザー

2019/10/29 03:21

WebViewをFrameLayoutとScrollviewで囲ってるのってなんででしょう?
ludolf

2019/10/29 03:42

>WebViewをFrameLayoutとScrollviewで囲ってるのってなんででしょう? 話すと長くなるのですが、簡潔にまとめるとWebView内でモーダルウィンドウを使用するとWebView全体の高さが指定されモーダルウィンドウの表示位置がおかしくなるため施策したときにこのような結果になりました、、 以前teratailで質問した内容なので下記記事に詳しく書いております、、 https://teratail.com/questions/211394
guest

回答2

0

ベストアンサー

BottomNavigationViewをCoordinatorLayoutの下に置く必要がある(何らかのBehaviorを設定したいor他のBehaviorの対象にしたい)のなら、ViewPager部分にはlayout_marginBottomを設定して余白を設けるようにするしかないです。

xml

1<ViewPager 2 ... 3 android:layout_marginBottom="@dimen/design_bottom_navigation_height"/> 4<BottomNavigationView 5 ... 6 android:layout_height="@dimen/design_bottom_navigation_height"/>

その必要がないのであれば、BottomNavigationViewをCoordinatorLayoutの外側に出してしまうのがいいと思います。あとはLinearLayoutなりで囲んであげれば重ならないように配置できます。

投稿2019/10/29 03:54

kakajika

総合スコア3131

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

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

ludolf

2019/10/29 04:17

いつもお世話になっております! やってみたところできましたー! しかし、一点動きがおかしくなった点があります、、 Toolbarをスクロールしたら非表示するためlayout_scrollFlagsを使用しているのですが、畳むのと合わせてボトムナビゲーションバーが上に動いてしまいます、、 投稿の問題としては解決したのですが、引き続きお聞きしてもよろしいでしょうか? (ViewPagerにlayout_marginBottomを追記したのと、BottomNavigationViewのlayout_heightをdimenに変更しました。)
kakajika

2019/10/29 04:41

BottomNavigationViewにapp:layout_anchorの指定をしているためかと思います。削除して試してみてください。
ludolf

2019/10/29 05:15

「app:layout_anchor="@+id/view_pager"」を削除しUPしてみるとボトムナビゲーションバーが最上部に来るようになりました、、 なのでLinearLayoutのverticalで囲み表示してみたのですが、ボトムナビゲーションバーがどこか彼方にきえました、、泣 下記自分がやったプログラムです。 </com.google.android.material.appbar.AppBarLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <androidx.viewpager.widget.ViewPager android:id="@+id/view_pager" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable = "true" android:layout_marginBottom="@dimen/design_bottom_navigation_height" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="@dimen/design_bottom_navigation_height" android:background="@color/white" app:layout_anchorGravity="bottom" app:itemHorizontalTranslationEnabled="false" app:labelVisibilityMode="labeled" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:menu="@menu/bottom_navigation_menu"/> </LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
kakajika

2019/10/29 05:44

なるほど、すみません。app:layout_anchorGravityとandroid:layout_gravityを見間違えてしまっていました。そうしたら、app:layout_anchorとapp:layout_anchorGravityは不要なので削除して、 android:layout_gravity="bottom" を追加してください。これで一番下に固定されてViewPagerの動きに連動することもなくなるはずです。
ludolf

2019/10/29 06:10

できました、毎度ありがとうございます! 原因はlayout_anchorでviewPagerの下に表示するようにしていたため連動して動いていたのですね。 あとdimenを使用してWebViewを下げる方法がとても勉強になりました! 本当にいつもありがとうございます!
guest

0

試してませんが、以下じゃダメですかね?

xml

1 <LinearLayout 2 android:layout_width="match_parent" 3 android:layout_weight="1" 4 android:layout_height="0dp" 5 android:orientation="vertical"> 6 7 <com.google.android.material.tabs.TabLayout 8 android:id="@+id/tabs" 9 android:layout_width="match_parent" 10 android:layout_height="35dp" 11 android:background="@color/white" 12 android:paddingTop="0dp" 13 android:paddingBottom="0dp" 14 android:paddingLeft="0dp" 15 android:paddingRight="0dp" 16 android:state_selected="true" 17 app:tabBackground="@drawable/tab_color_selector" 18 app:tabGravity="fill" 19 app:tabMaxWidth="0dp" 20 app:tabMode="fixed" 21 app:tabTextAppearance="@style/TabText" /> 22 23 </com.google.android.material.appbar.AppBarLayout> 24 <androidx.viewpager.widget.ViewPager 25 android:id="@+id/view_pager" 26 android:layout_width="match_parent" 27 android:layout_height="match_parent" 28 android:focusable = "true" 29 app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 30 31 </LinearLayout>

投稿2019/10/27 14:02

jun74

総合スコア338

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

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

ludolf

2019/10/29 02:40

回答ありがとうございます! やってみたのですが、下記のエラーが出ます。 ↓ エラー文 ↓ 要素タイプ"LinearLayout"は、対応する終了タグ"</LinearLayout>"で終了する必要があります。 回答いただいたやり方のように閉じタグを囲むといったやり方があるのでしょうか?
jun74

2019/10/29 02:45

はい。
ludolf

2019/10/29 02:55

勉強になります! ただ今回エラーが出た内容は「</com.google.android.material.appbar.AppBarLayout>」の閉じタグ内にLenearLayoutを記述しないとエラーがでると考えておりますが、どこが違うのでしょうか、、 すみませんが引き続き教え願えないでしょうか?
jun74

2019/10/29 03:03

すみません。。「</com.google.android.material.appbar.AppBarLayout>」を「<com.google.android.material.tabs.TabLayout」の上(LinearLayoutの上)にしたら、どうなるでしょうか?
ludolf

2019/10/29 03:06

「<com.google.android.material.bottomnavigation.BottomNavigationView」ボトムナビゲーションバーが上に最上部にきてWebViewが表示されていない状態になりました、、
jun74

2019/10/29 03:17

更に一番外のCoordinatorLayoutの内側を <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> で囲ったらどうでしょう?
ludolf

2019/10/29 03:36

意図した追記なのか不安なので下記追記した内容です! エラーは先ほどと変わらないです。 <androidx.coordinatorlayout.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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.appbar.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:paddingTop="8dp" android:paddingBottom="8dp" app:layout_scrollFlags="scroll|snap"> <androidx.appcompat.widget.AppCompatImageButton android:id="@+id/logo_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:adjustViewBounds="true" android:scaleType="fitCenter" /> </androidx.appcompat.widget.Toolbar> </com.google.android.material.appbar.AppBarLayout> <LinearLayout android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dp" android:orientation="vertical"> <com.google.android.material.tabs.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="35dp" android:background="@color/white" android:paddingTop="0dp" android:paddingBottom="0dp" android:paddingLeft="0dp" android:paddingRight="0dp" android:state_selected="true" app:tabBackground="@drawable/tab_color_selector" app:tabGravity="fill" app:tabMaxWidth="0dp" app:tabMode="fixed" app:tabTextAppearance="@style/TabText" /> <androidx.viewpager.widget.ViewPager android:id="@+id/view_pager" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable = "true" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </LinearLayout> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/white" app:layout_anchor="@+id/view_pager" app:layout_anchorGravity="bottom" app:itemHorizontalTranslationEnabled="false" app:labelVisibilityMode="labeled" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:menu="@menu/bottom_navigation_menu"/> </LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
kakajika

2019/10/29 03:56

CoordinatorLayout.Behaviorを設定したいViewはCoordinatorLayout直下に置く必要があるので、LinearLayoutで囲んでしまうと動作しないと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問