android-layout - 协调布局不适用于选项卡布局

标签 android-layout android-fragments android-studio android-coordinatorlayout android-tablayout

美好的一天,您能帮我纠正这个问题吗?
在我的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

我真的需要你的帮助。我被这个卡住了。
先感谢您。

最佳答案

修复起来应该很容易:


ViewPager删除AppBarLayout
ViewPager作为同级添加到AppBarLayout并为其添加app:layout_behavior="@string/appbar_scrolling_view_behavior"并将layout_widthlayout_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/

相关文章:

android - 找出屏幕上当前显示的是哪个布局文件

java - 使布局适应所有屏幕分辨率 - Android

java - fragment 到 Activity 动画不适用于 overridePendingTransition();

java - fragment 内单选按钮 OnCheckedChangeListener 错误

android - TabLayout 和底部导航

java - 实现搜索栏并在空对象引用错误上获取 'java.lang.Object[] java.util.Collection.toArray()'

android-studio - 错误 :Failed to resolve: runtime

android - 如何避免列表之间出现双边框?

android - 要像海豚浏览器一样创建隐藏在 View 左侧的侧边栏

java - 在首选项更改监听器上 - 单击运行两次后