【发布时间】:2016-08-05 08:01:52
【问题描述】:
如图所示。这两个没有正确对齐。我无法理解为什么会这样。
我的工具栏位于 app_bar_main.xml 中的协调器布局中,而我的选项卡布局位于 fragment_main 中。我没有在协调器布局中添加选项卡布局,因为我不想在我的所有视图中显示它,只是在我的片段主文件中。
我在 app_bar_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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
fragment_main.xml 中的代码:
<FrameLayout 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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:id="@+id/tabs"
android:backgroundTint="#FFFFFF"
app:tabMode="fixed"
app:tabGravity="fill"
app:popupTheme="@style/AppTheme.PopupOverlay">
</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"
android:id="@+id/view_pager_1">
</android.support.v4.view.ViewPager>
</FrameLayout>
你能告诉我我做错了什么吗?
【问题讨论】:
-
在样式中为工具栏设置 elevation 0
-
海拔为 0 @PiyushGupta。
-
检查我的代码。 @PiyushGupta
-
@AndroidGeek 请刷新。
标签: android android-fragments android-toolbar android-tablelayout