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

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

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

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

Q&A

解決済

1回答

5098閲覧

スクロールビューとフッターの組み合わせ:フッターを常に表示したい。

adk

総合スコア12

Android Studio

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

1グッド

0クリップ

投稿2019/10/02 05:30

編集2019/10/03 01:12

現状,AndroidStudioでツールバー付きのスクロールビューとその下にフッターを付けたアクティビティを作っています。

スクロールビューはツールバーを持っており、そのツールバーは「app:layout_scrollFlags="scroll|enterAlways"」で
下にスクロールすると表示されなくなるようにしています。

スクロールする内容の中身は<include layout="@layout/content" />で別のxmlファイルを持ってきています。

https://techblog.yahoo.co.jp/android/androidcoordinatorlayout/

を参考にスクロールビューの中身は下記のような構造で作成しています。

xml

1<CoordinatorLayout> 2   <AppBarLayout> 3     <CollapsingToolbarLayout> 4       <Toolbar /> 5     </CollapsingToolbarLayout> 6   </AppBarLayout> 7   <include layout="@layout/content_scrolling" /> 8</CoordinatorLayout>

このレイアウトの下に常に表示されるフッターを付けようとしているのですが、現状フッターが一番下に固定されており、
キーボードが出ると隠れてしまいます。

キーボードが出るとフッターがキーボードと一緒に押し上げられて常に表示される挙動を望んでいるのですが、何が悪いのかわかりません。
アドバイスを頂けませんでしょうか。

現状のアプリの構成は

xml

1<RelativeLayout> 2 3  <CoordinatorLayout> 4     <AppBarLayout> 5       <CollapsingToolbarLayout> 6         <Toolbar /> 7       </CollapsingToolbarLayout> 8     </AppBarLayout> 9     <include layout="@layout/content_scrolling" /> 10  </CoordinatorLayout> 11 12  <fragment></fragment> 13 14</RelativeLayout>

としています。詳細なコードは下記のとおりです。

xml

1<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:app="http://schemas.android.com/apk/res-auto" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical"> 7 8 9 10 11 <androidx.coordinatorlayout.widget.CoordinatorLayout 12 android:layout_width="fill_parent" 13 android:layout_height="fill_parent" 14 android:layout_above="@+id/SM_bottomFrag" 15 android:layout_marginBottom="0dp" 16 android:fitsSystemWindows="true" 17 tools:context=".Activity"> 18 19 20 <com.google.android.material.appbar.AppBarLayout 21 android:id="@+id/app_bar" 22 android:layout_width="match_parent" 23 android:layout_height="100dp" 24 android:fitsSystemWindows="true" 25 android:theme="@style/AppTheme.AppBarOverlay"> 26 <com.google.android.material.appbar.CollapsingToolbarLayout 27 android:id="@+id/toolbar_layout" 28 android:layout_width="match_parent" 29 android:layout_height="match_parent" 30 android:fitsSystemWindows="true" 31 app:contentScrim="?attr/colorPrimary" 32 app:layout_scrollFlags="scroll|enterAlways" 33 app:toolbarId="@+id/toolbar"> 34 <androidx.appcompat.widget.Toolbar 35 android:id="@+id/toolbar" 36 android:layout_width="match_parent" 37 android:layout_height="?attr/actionBarSize" 38 app:layout_collapseMode="pin" 39 app:title="タイトル画面" 40 app:popupTheme="@style/AppTheme.PopupOverlay" /> 41 </com.google.android.material.appbar.CollapsingToolbarLayout> 42 </com.google.android.material.appbar.AppBarLayout> 43 44 <include layout="@layout/content" /> 45 46 </androidx.coordinatorlayout.widget.CoordinatorLayout> 47 48 49 50 51 52 <fragment」 53 android:id="@+id/SM_bottomFrag" 54 android:name="com.example.myapplication.BottomFragment" 55 android:layout_width="match_parent" 56 android:layout_height="wrap_content" 57 android:layout_alignParentBottom="true" 58 tools:layout="@layout/fragment_bottom" /> 59 60 61</RelativeLayout>

追記//////////////////////////////////////////////////////////////////////////////////
教えていただいたフッター固定法をもとに以下のように変えると、うまくいきます。

AndroidManifest

1<activity android:windowSoftInputMode="adjustResize">

xml

1<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 android:layout_width="match_parent" 3 android:layout_height="match_parent" 4 xmlns:tools="http://schemas.android.com/tools"> 5 6 <ScrollView 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 android:layout_above="@+id/SM_bottomFrag"> 10 11 <include layout="@layout/content" /> 12 13 </ScrollView> 14 <fragment 15 android:id="@+id/SM_bottomFrag" 16 android:name="com.example.myapplication.BottomFragment" 17 android:layout_width="match_parent" 18 android:layout_height="wrap_content" 19 android:layout_alignParentBottom="true" 20 tools:layout="@layout/fragment_bottom" 21 android:layout_weight="1.0"/> 22</RelativeLayout>

ですが、この<ScrollView>で囲まれた部分が

xml

1<androidx.coordinatorlayout.widget.CoordinatorLayout 2 android:layout_width="fill_parent" 3 android:layout_height="fill_parent" 4 android:layout_above="@+id/SM_bottomFrag" 5 android:layout_marginBottom="0dp" 6 android:fitsSystemWindows="true" 7 tools:context=".Activity"> 8 <com.google.android.material.appbar.AppBarLayout 9 android:id="@+id/app_bar" 10 android:layout_width="match_parent" 11 android:layout_height="100dp" 12 android:fitsSystemWindows="true" 13 android:theme="@style/AppTheme.AppBarOverlay"> 14 <com.google.android.material.appbar.CollapsingToolbarLayout 15 android:id="@+id/toolbar_layout" 16 android:layout_width="match_parent" 17 android:layout_height="match_parent" 18 android:fitsSystemWindows="true" 19 app:contentScrim="?attr/colorPrimary" 20 app:layout_scrollFlags="scroll|enterAlways" 21 app:toolbarId="@+id/toolbar"> 22 <androidx.appcompat.widget.Toolbar 23 android:id="@+id/toolbar" 24 android:layout_width="match_parent" 25 android:layout_height="?attr/actionBarSize" 26 app:layout_collapseMode="pin" 27 app:title="タイトル画面" 28 app:popupTheme="@style/AppTheme.PopupOverlay" /> 29 </com.google.android.material.appbar.CollapsingToolbarLayout> 30 </com.google.android.material.appbar.AppBarLayout> 31 32 <include layout="@layout/content" /> 33 34 </androidx.coordinatorlayout.widget.CoordinatorLayout>

だとやはりフッターは下に固定されてしまいます。固定の原因はCoordinatorLayoutの中身に原因があると思われます。
(置き換える際にはAndroidManifestに android:theme="@style/AppTheme.NoActionBar" を足しています)

ツールバーをapp:layout_scrollFlags="scroll|enterAlways"の挙動で動かすのは外したくないです。

なので、主な解決策としては

1.CoordinatorLayoutの中身でフッターを固定している設定を特定し、外す

2.CoordinatorLayoutを使わず、別のレイアウトを使ってツールバーをの
app:layout_scrollFlags="scroll|enterAlways"の挙動を実現する

のほうが良いのかなと思っています。このどちらかのやり方についてお教え願えませんでしょうか。

medka34👍を押しています

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

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

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

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

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

jimbe

2019/10/02 07:54

コード類は「```」の行で囲うとインデントをつけた状態で表示できます. xml であれば最初の「```」を「```xml」とすることでそれらしくフォーマットされますので, プレビューを確認しながら修正されては如何でしょうか.
adk

2019/10/02 08:21

>>ご指摘ありがとうございます。修正してみました。
退会済みユーザー

退会済みユーザー

2019/10/02 15:08

jimbeさんのおっしゃってる「```」はそういう意味じゃなく。 ``` (バッククォート3つ) の行から```の行で囲め、という意味です。 ```xml (ここにコードを書く) ``` 質問への追記・修正欄では反映されませんが、質問では↑のように書けばスタイルがついて見やすくなります。 (というか「それらしくフォーマットされます」と書いているのに何も起こらない時点でおかしいなと思ってください)
adk

2019/10/02 23:44

>>度々のアドバイスありがとうございます。 そういう意味だったのですね。修正いたしました。
guest

回答1

0

ベストアンサー

以下により実現できるはずです。
例題ではScrollViewのweightを1にするとありますが、ソフトウェアキーボード分の表示を縮めて、
キーボードがなくなったら戻したいレイアウトに対して「weightを1」を付ければ良かったはずです。

Androidアプリでキーボードの上までスクロールできるようにする

投稿2019/10/02 20:31

jun74

総合スコア338

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

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

adk

2019/10/03 01:16

>>ご回答ありがとうございます。 ご紹介のHPの操作をもとに確かにフッターの湖底はできましたが、ScrollViewの部分を CoordinatorLayoutに変えると、フッターが固定されたままです。 詳細は本文に追記いたしました。 大まかな解決法について考えてみたのですが、これについて もしアドバイスがあれば教えて頂けませんでしょうか。
adk

2019/10/03 01:42 編集

解決しました!CoodinatorLayoutの android:fitsSystemWindows="true" を外し、 <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@+id/SM_bottomFrag" android:layout_marginBottom="0dp" tools:context=".Activity"> とすればうまくいきました! ちなみに<com.google.android.material.appbar.AppBarLayout>内の android:fitsSystemWindows="true"は外していません。 ご協力ありがとうございました!!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問