2

美好的一天你能帮我纠正这个问题吗? 在我的activity_main.xml中,我使用了协调布局以便我的AppBar可以工作。协调布局不适用于选项卡布局

<android.support.v4.widget.DrawerLayout 
android:id="@+id/drawer_layout" 
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:fitsSystemWindows="true" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
tools:context="com.eccp.projects.ecosavers.ecosavers.activities.eco_detailed_information"> 

<!--COORDINATOR LAYOUT--> 
<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/coordinator_layout" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="#ffffff"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark"> 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/tool_bar" 
      /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tablayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      android:elevation="4dp" 
      app:tabMode="fixed" 
      app:tabGravity="fill"/> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:layout_weight="1" 
      android:background="#ffffff"/> 
    </android.support.design.widget.AppBarLayout> 


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

<android.support.design.widget.NavigationView 
    android:id="@+id/navigation_view" 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content" 
    android:layout_gravity="start" 
    app:headerLayout="@layout/header" 
    app:menu="@menu/drawer"/> 

,在我的第一个标签我 - 组织饲料不工作,它卡住,不会让我来向上滑动显示出来的饲料。但有时它会滑动,但是,布局有重叠。我只是将我的cardview_items.xml作为概述来介绍它的外观。

<RelativeLayout 
android:orientation="vertical" 
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:scrollbarAlwaysDrawVerticalTrack="true" 
android:fitsSystemWindows="true" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
tools:context="com.eccp.projects.ecosavers.ecosavers.activities.eco_detailed_information"> 

<!--COORDINATOR LAYOUT--> 
    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 
     android:layout_gravity="fill_vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_marginTop="1dp"> 

      <!--Dummy Value 1--> 
      <include 
       android:id="@+id/card_item" 
       layout="@layout/eco_events_cardview" /> 

      <include 
       android:id="@+id/card_item" 
       layout="@layout/eco_events_cardview" /> 

     </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 

enter image description here

我真的需要你的帮助。我坚持这一个。 预先感谢您。

回答

0

应该很容易解决:

  1. AppBarLayout
  2. 删除ViewPager添加ViewPager作为同级的AppBarLayout并添加它app:layout_behavior="@string/appbar_scrolling_view_behavior"并设置layout_width & layout_heightmatch_parent

所以你的布局应该看起来像:

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

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/tool_bar"/> 

     <android.support.design.widget.TabLayout 
      .../> 
    </android.support.design.widget.AppBarLayout> 
    <android.support.v4.view.ViewPager 
     ..... 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

我希望它有帮助。