TabLayout在Appbar布局中使用时不可见

时间:2018-01-11 04:01:46

标签: android android-tablayout android-collapsingtoolbarlayout drawerlayout android-appbarlayout

这是我的main_activity.xml代码

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

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

    <include
        android:id="@+id/appbar"
        layout="@layout/appbar_main" />

</LinearLayout>


<FrameLayout
    android:layout_width="250dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:background="@android:color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <com.mindorks.placeholderview.PlaceHolderView
        android:id="@+id/drawerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"/>

</FrameLayout>

这是我的appbar_main.xml活动代码

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/MyAppbar"
    android:layout_width="match_parent"
    android:layout_height="256dp"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true">

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

            <ImageView
                android:layout_gravity="center"
                android:id="@+id/imageView3"
                android:layout_width="85dp"
                android:layout_height="61dp"
                android:src="@drawable/badge"
                android:layout_marginTop="10dp" />

            <TextView
                android:layout_gravity="center"
                android:id="@+id/nameTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:text="Krishna Pujar"
                android:textColor="@color/hintTextColor" />

            <TextView
                android:id="@+id/university"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="JNV Dharwad"
                android:textColor="@color/hintTextColor" />

        </LinearLayout>

        <LinearLayout
            android:layout_gravity="center"
            android:layout_marginTop="60dp"
            android:orientation="vertical"
            android:layout_width="300dp"
            android:layout_height="40dp">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/level"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Level - XX"
                    android:textColor="@color/hintTextColor" />

                <TextView
                    android:id="@+id/points"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="166dp"
                    android:text="1XX Points"
                    android:textColor="@color/hintTextColor"/>

            </LinearLayout>

            <ProgressBar
                android:layout_gravity="center"
                android:id="@+id/progressBar"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="8dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:background="#ffffff"
                android:minHeight="60dp"
                android:minWidth="220dp" />

        </LinearLayout>

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

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:minHeight="60dp"
        tabGravity="fill"
        tabIndicatorColor="#000000"
        tabMode="fixed"
        tabSelectedTextColor="#000000"
        android:background="@color/tabs"/>



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

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

问题: 我的工具栏是一半可见的 2.标签不可见

图片供您参考:

  1. 我的工具栏有一半可见 预期:

    实际值: broken toolbar Tool bar is properly visible with FLA icon

    1. 标签不可见 预期: Tabs are visible clearly, LEARNING AND QUIZ
    2. 实际值: Tabs not visible in this picture

1 个答案:

答案 0 :(得分:0)

app_bar.xml

    

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

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/black_shadow_center" />

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

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

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="85dp"
                    android:layout_height="61dp"
                    android:layout_gravity="center"
                    android:layout_marginTop="10dp"
                    android:src="@drawable/fav" />

                <TextView
                    android:id="@+id/nameTxt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="8dp"
                    android:text="Krishna Pujar"
                    android:textColor="@color/colorPrimaryDark" />

                <TextView
                    android:id="@+id/university"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="JNV Dharwad"
                    android:textColor="@color/colorPrimaryDark" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="40dp"
                android:layout_gravity="center"
                android:layout_marginTop="60dp"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/level"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Level - XX"
                        android:textColor="@color/colorPrimaryDark" />

                    <TextView
                        android:id="@+id/points"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="166dp"
                        android:text="1XX Points"
                        android:textColor="@color/black_shadow_center" />

                </LinearLayout>

                <ProgressBar
                    android:id="@+id/progressBar"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:layout_width="match_parent"
                    android:layout_height="8dp"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center"
                    android:layout_marginTop="5dp"
                    android:background="#ffffff"
                    android:minHeight="60dp"
                    android:minWidth="220dp" />

            </LinearLayout>

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



        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            tabGravity="fill"
            tabIndicatorColor="#000000"
            tabMode="fixed"
            tabSelectedTextColor="#000000"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/colorPrimary"
            android:minHeight="60dp" />


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

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/pager_header"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

activity_main.xml中

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <include
            android:id="@+id/appbar"
            layout="@layout/appbar_main" />

    </LinearLayout>


    <FrameLayout
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="@android:color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <com.mindorks.placeholderview.PlaceHolderView
            android:id="@+id/drawerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical" />

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