1

ユーザーがのタブのToolbar1 つ (によって提供される) でスクロールしたときに折りたたむようにしたいと思います。TabLayoutViewPager

これは私が望む機能です:

ここに画像の説明を入力

ここに画像の説明を入力

ただし、私のレイアウトはスクロールしないだけでなく、下部のコンテンツを切り取ります (正確には、ツールバーの高さである 48dp を切り取ります)。

ここに画像の説明を入力

ViewPager を使用して、各 Fragment をタブとして表示します。フラグメントは、単純ScrollViewTextView. レイアウトは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/ueber_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways" />

        <android.support.design.widget.TabLayout
            android:id="@+id/ueber_tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:tabIndicatorColor="@android:color/white"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/ueber_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

各フラグメントには次のレイアウトがあります。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:id="@+id/ueber_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="14sp"
        android:textColor="#000000"
        android:linksClickable="false"
        android:textColorLink="#000000"
        android:fontFamily="serif"
        android:padding="16dp"/>

</ScrollView>

ViewPager は ViewPagerAdapter によって設定されます。

ViewPager viewPager = (ViewPager) findViewById(R.id.ueber_viewpager);

ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFrag(new ContentFragment(), "Über");
adapter.addFrag(new ContentFragment(), "Impressum");
adapter.addFrag(new ContentFragment(), "Lizenzen");
viewPager.setAdapter(adapter);

TabLayout tabLayout = (TabLayout) findViewById(R.id.ueber_tabLayout);
tabLayout.setupWithViewPager(viewPager);
4

2 に答える 2