前提・実現したいこと
JAVAのアプリ開発を初めて4ヶ月ほどの初心者です。
現在JAVAでAppBarLayout+TabLayout+ViewPagerを主に使いレイアウトを作成しています。
画面は、ユーザーのマイページとして使う予定で、
TabLayoutの上部にアイコン画像や名前等を表示するレイアウトが入っており、下へスクロールするとアイコン等を表示しているレイアウトがスクロールされ隠れ、下のViewPagerのレイアウト(ListView)がスクロールして閲覧できる、といった仕様の画面を作成しています。
発生している問題
tabから上を触ってスクロールした場合、上部のレイアウト、下のViewPagerも一緒にスクロールされるのはいいのですが、下にスクロールしていった場合(TabLayoutのみが画面の上部にあり、その下でViewPagerのレイアウトがスクロールできる状態)になったときに、上のアイコン等のレイアウトを表示するにはTabLayoutを触ってスクロールしないと表示ができない仕様になってしまっています。
このままだと、仕様を知らない人は画面に広く表示されているViewPagerのレイアウトのみを触ってスクロールしようとした時、「上に戻れなくなった」と思ってしまうし、仕様を知っている作った私でさえも使いずらいと思っているほどなので、どうにか、ViewPagerのレイアウトの一番上までスクロールしたらそのままTabLayout上のアイコンなどのレイアウトを表示できるようにしたいです。
該当のソースコード
現在のソースは以下になります。
part_user_page_tab_layout.xml
xml
1<?xml version="1.0" encoding="utf-8"?> 2<android.support.design.widget.CoordinatorLayout 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:android="http://schemas.android.com/apk/res/android" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:fitsSystemWindows="true"> 8 9 <android.support.design.widget.AppBarLayout 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content" 12 android:background="@null"> 13 14 <include layout="@layout/my_page_header_view" /> 15 16 <android.support.design.widget.TabLayout 17 android:id="@+id/tabLayout" 18 style="@style/TabLayout" 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 app:tabTextAppearance="@style/CustomTabText"/> 22 23 </android.support.design.widget.AppBarLayout> 24 25 <android.support.v4.view.ViewPager 26 android:id="@+id/viewPager" 27 android:layout_width="match_parent" 28 android:layout_height="match_parent" 29 app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 30 31</android.support.design.widget.CoordinatorLayout>
my_page_header_view.xml
xml
1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:app="http://schemas.android.com/apk/res-auto" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:orientation="vertical" 6 app:layout_scrollFlags="scroll|enterAlwaysCollapsed"> 7 8 <FrameLayout 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content" 11 android:layout_marginBottom="@dimen/marginSmall"> 12 13 <FrameLayout 14 android:id="@+id/profile_background" 15 android:layout_width="match_parent" 16 android:layout_height="64dp" /> 17 18 <ImageButton 19 android:id="@+id/setting_button" 20 android:layout_width="32dp" 21 android:layout_height="32dp" 22 android:layout_marginTop="72dp" 23 android:layout_marginEnd="@dimen/marginSmall" 24 android:layout_gravity="end" 25 android:background="@null" 26 app:srcCompat="@drawable/mypage_config" /> 27 28 <LinearLayout 29 android:layout_width="match_parent" 30 android:layout_height="wrap_content" 31 android:orientation="vertical"> 32 33 <ImageView 34 android:id="@+id/user_icon" 35 android:layout_width="128dp" 36 android:layout_height="128dp" 37 android:layout_gravity="center" /> 38 39 </LinearLayout> 40 41 </FrameLayout> 42 43 <TextView 44 android:id="@+id/user_name" 45 android:layout_width="wrap_content" 46 android:layout_height="wrap_content" 47 android:layout_margin="@dimen/marginSmall" 48 android:paddingStart="@dimen/marginXBasic" 49 android:paddingEnd="@dimen/marginXBasic" 50 android:layout_gravity="center" 51 android:textSize="@dimen/fontXBasic" 52 android:textStyle="bold" 53 android:textColor="@color/colorBlack" /> 54 55</LinearLayout>
試したこと
以下のページを主に参考に作成しました
http://chocolattips.hatenablog.com/entry/2017/03/12/000000
https://qiita.com/tacksman/items/f19891506e55668ffc06
まだまだ知識が足らずこちらへ投稿するのも初めてなので、
書くべきこと等抜けていましたら言っていただけると幸いです。
また、AppBarLayout等を使って作成していますが、ViewPagerと一緒に上のレイアウトもスクロールできるような方法がありましたら、是非ご教授いただきたいです。
よろしくお願いします。
あなたの回答
tips
プレビュー