2016-04-10 9 views
2

私はAndroid開発には新しく、次の問題に直面しています。 これは私の主な活動のレイアウトです:各タブのViewPagerは画面の下に広がっています

<?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.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:tabIndicatorColor="@color/white" 
       app:tabTextColor="@color/selected_text" 
       app:tabSelectedTextColor="@color/white"/> 

     </android.support.v7.widget.Toolbar> 

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

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

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

ViewPagerに続いて私は私のリストビューを移入Iフラグメントを持っており、これはそれらの1

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/colorPrimary" 
    android:id="@+id/linear_layout" 
    tools:context=".fragments.Reviews"> 

    <RatingBar 
     android:id="@+id/review_totalRating" 
     style="?android:attr/ratingBarStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:numStars="5" 
     android:stepSize=".5" 
     android:isIndicator="true" 
     android:progressTint="@color/golden" 
     android:layout_gravity="center" 
     android:paddingTop="10dp" 
     android:paddingBottom="5dp" /> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="8dp" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:id="@+id/listView_reviews" /> 

</LinearLayout> 

のレイアウトですレイアウトが別のXMLファイルで定義されている項目。私の問題はViewPagerのlayout_heightにあります:これはmatch_parentに設定されましたが、要素は画面の最後まで拡張され、ListViewの最後の要素はナビゲーションボタンでカバーされます。 これはデザインエディタに表示されます ViewPager overflow

ナビゲーションボタンの前に要素を停止させるにはどうすればよいですか?

答えて

5

私もこの問題に直面しました。 CoordinatorLayoutには、AppBarLayoutの動作が原因です。デフォルトでは、テンプレートからプロジェクトを作成するときに、Toolbarを隠してレイアウトを設定します。あなたのサンプルを実行し、それを確認することができます - ツールバーをスワイプするだけで非表示になり、ViewPagerは上に移動して、画面の下部に正しく貼り付けられます。

場合によっては解決策ではないので、Toolbarからapp:layout_scrollFlags属性を削除してこの動作を無効にすることができます。その後、ツールバーは移動不能になり、ViewPagerは正確に自身の高さを計算します。

+0

私も同じ問題に直面し、あなたの提案は参考になりました。それは、リストビューがrecyclerviewの代わりに使用されているのでしょうか? – dna

1

LinearLayoutをCoordinatorLayoutの唯一の子として使用して解決しました。それ以外はすべてLinearLayoutの子になります。私にとっては、単純な回避策ではなく、最終的な解決策であるように思えますが、今は機能します。これが今の私の主な活動のレイアウトです:

<?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"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:tabIndicatorColor="@color/orange_050" 
       app:tabSelectedTextColor="@color/orange_050" 
       app:tabTextColor="@color/orange_050"/> 

     </android.support.v7.widget.Toolbar> 

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

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

</LinearLayout> 

関連する問題