【发布时间】:2019-06-29 18:50:19
【问题描述】:
我正在尝试将 AppBarLayout 与 Toolbar、TabLayout 组件和 Viewpager 一起使用,但我在工具栏和 tablayout 之间发现了一个黑色间隙,并且不确定为什么。我查看了这里的一些示例,但它们不起作用。
我把我的问题的图片。
XML
<RelativeLayout
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:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/home_appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/white"
app:contentInsetStart="@dimen/margin_8"
app:contentInsetStartWithNavigation="@dimen/margin_8"
app:layout_collapseMode="pin"
app:paddingStart="0dp"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:titleMarginStart="@dimen/margin_8">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="toolbar"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/rosa_apelucy">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
app:tabMode="fixed"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/transparent"
android:elevation="6dp"
app:tabTextColor="@color/grey"
app:tabSelectedTextColor="@color/pink"
app:tabIndicatorColor="@color/pink"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
</RelativeLayout>
更新问题
<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:background="@color/blanco">
<android.support.design.widget.AppBarLayout
android:id="@+id/home_appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:contentInsetStart="@dimen/margin_8"
app:contentInsetStartWithNavigation="@dimen/margin_8"
app:layout_collapseMode="pin"
app:paddingStart="0dp"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:titleMarginStart="@dimen/margin_8">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="toolbar"/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
app:tabMode="fixed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:elevation="6dp"
android:minHeight="?android:attr/actionBarSize"
app:tabTextColor="@color/gris_oscuro"
app:tabSelectedTextColor="@color/rosa_apelucy"
app:tabIndicatorColor="@color/rosa_apelucy"
android:layout_marginTop="@dimen/margin_25"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
标签: android android-viewpager android-toolbar android-tablayout