2016-07-16 6 views
0

Navigation barとScrollingアクティビティを組み合わせたViewPagerを作成するアプリケーションを作っています。私はコードを提供しません。なぜなら、私は両方のAndroid Studioテンプレートコードをマージして使用するだけなので、私はあなたにコードを提供しません。ViewPagerとスクロールアクティビティの混在

enter image description here

これは、アプリケーションがどのように見えるかです。

スクロールすると問題が発生します。

タイトルバーが表示されるため、ページの最後には到達しません。

enter image description here

そして、あなたはそれを隠すためにタイトルを画面の上部に指を動かすとスクロールする必要があるページの一番下までスクロールするために

enter image description here

私はこの問題のいくつかのトリッキーな解決策を見つけた:

  1. は、ページの末尾にスペースを作ります。

タイトルを一定にしかし、これらのソリューションは、私には興味がありません。

次の手順でスクロールが必要です。

  1. スクロールを開始すると、タイトルが上に移動して消えています。

  2. 次に、フラグメントがページの最後までスクロールしています。事前に


感謝。

答えて

0

たぶん、あなたはCoordinatorLayoutを使用して、ツールバー上に置くことができます。

app:layout_scrollFlags="scroll|enterAlways" 

そして、あなたのビューのページャに行動を置く:

app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" 

完全なXMLは、このようなものです:

  1. あなたのactiviy xml:

    たとえば、content_main.xmlのためのあなたの含まXMLで
  2. <?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.DrawerLayout   
        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:id="@+id/drawer_layout" 
        android:layout_width="match_parent"  
        android:layout_height="match_parent" 
        android:fitsSystemWindows="true" tools:openDrawer="start"> 
    
    <include layout="@layout/content_main" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 
    
    <android.support.design.widget.NavigationView 
        android:id="@+id/nav_view" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:layout_gravity="start" android:fitsSystemWindows="true" 
        app:headerLayout="@layout/nav_header_main" 
        app:menu="@menu/menu_main_drawer" /> 
    
    </android.support.v4.widget.DrawerLayout> 
    
    、:

    <?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" 
        xmlns:tools="http://schemas.android.com/tools" 
        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:theme="@style/AppTheme.AppBarOverlay"> 
    
        <android.support.v7.widget.Toolbar 
         android:id="@+id/toolbar" 
         android:layout_width="match_parent" 
         android:layout_height="?attr/actionBarSize" 
         android:background="?attr/colorPrimary" 
    
         app:layout_scrollFlags="scroll|enterAlways" 
         app:popupTheme="@style/AppTheme.PopupOverlay"> 
        </android.support.v7.widget.Toolbar> 
    
        </android.support.design.widget.AppBarLayout> 
    
        <android.support.v4.view.ViewPager 
        android:id="@+id/vp_main" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" /> 
    
    </android.support.design.widget.CoordinatorLayout> 
    
+0

アプリ:layout_scrollFlags = "スクロール| enterAlways" と アプリ:layout_behavior = "android.support.design.widget。 AppBarLayout $ ScrollingViewBehavior "は既に実装されており、正しく動作しません。 –

+0

スクロールするのに十分なアイテムがありますか?ViewPagerの高さ以上にアイテムがなければ非表示になりません – faruk

+0

CollapsingToolbarLayoutに必要なlayout_scrollFlagsとツールバーには何か –

関連する問題