美好的一天,您能帮我纠正这个问题吗?
在我的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>
我真的需要你的帮助。我被这个卡住了。
先感谢您。
最佳答案
修复起来应该很容易:
从ViewPager
删除AppBarLayout
将ViewPager
作为同级添加到AppBarLayout并为其添加app:layout_behavior="@string/appbar_scrolling_view_behavior"
并将layout_width
和layout_height
设置为match_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>
希望对您有所帮助。
关于android-layout - 协调布局不适用于选项卡布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34784882/