繁体   English   中英

AppBarLayout 工具栏 TabLayout ViewPager DrawerLayout

[英]AppBarLayout Toolbar TabLayout ViewPager DrawerLayout

我想将 DrawerLayout 与连接到 TabLayout 的 ViewPager 结合使用。 最重要的是我想要工具栏。

然而,这段代码带来了最好的结果,当抽屉打开时它隐藏了工具栏。

<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.v4.widget.DrawerLayout
    android:id="@+id/my_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <android.support.v7.widget.Toolbar
            android:id="@+id/my_awesome_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:minHeight="?attr/actionBarSize" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="0dp"

            android:paddingTop="0dp"
            app:tabGravity="fill"


            app:tabMode="scrollable" />

        <com.sourcecastle.commons.controls.CustomViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />


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

    <LinearLayout
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="?attr/theme_background_color"
        android:choiceMode="singleChoice"

        android:orientation="vertical">


        <TextView
            android:id="@+id/tvTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:gravity="center"
            android:text="00:00:00"
            android:textAppearance="?android:attr/textAppearanceLarge" />


        <TextView
            android:id="@+id/tvDistance"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"

            android:text="123km"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:visibility="gone" />

        <LinearLayout
            android:id="@+id/llMap"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">

            <fragment
                android:id="@+id/speedFragment"
                class="com.sourcecastle.logbook.fragments.SpeedFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"

                android:layout_weight=".60" />

            <fragment
                android:id="@+id/mMap"
                class="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight=".40" />
        </LinearLayout>

        <TextView
            android:id="@+id/tvEnlarge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"

            android:gravity="center"
            android:text="@string/enlarge"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

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

截图1 截图2

我已经尝试了几乎所有的组合并阅读了很多帖子。 还有这里的类似问题: Android CoordinatorLayout + TabLayout + ViewPager Toolbar not hidden on scroll

当我带出 AppBarLayout 并将 ViewPager 留在 DrawerLayout 中时,ViewPager 在 TabLayout 和 Toolbar 之下。

为此线性布局提供工具栏高度的顶部边距

<LinearLayout
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="?attr/theme_background_color"
    android:choiceMode="singleChoice"
    android:layout_marginTop="?attr/actionBarSize"
    android:orientation="vertical">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM