我试图在片段中使用协调器布局和AppBarLayout。我的目标是拥有一个标题,而不是在滚动时隐藏,但保留活动内部的标题栏,并且是其他片段所必需的。
我的问题是,当我向下滚动时,标题并未完全隐藏。有一个状态栏高度仍然可见的部分。我不知道怎么让它完全消失。
以下是一些scrren捕获,使其更容易理解:
这是布局xml:
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_dark"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="@dimen/general_padding"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginTop="100dp"
android:layout_margin="@dimen/general_padding"
android:background="@android:color/holo_green_light"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
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.CoordinatorLayout>
使用此布局的片段中的onCreateView()方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tabs, container, false);
mUnbinder = ButterKnife.bind(this, view);
mTabsPresenter.subscribe(this);
TabsPagerAdapter adapter = new TabsPagerAdapter(getChildFragmentManager());
mPager.setAdapter(adapter);
mTabs.setupWithViewPager(mPager);
mTabs.getTabAt(0).setText("_Maintenance");
mTabs.getTabAt(1).setText("_History");
mTabs.getTabAt(2).setText("_Costs");
setHasOptionsMenu(true);
return view;
}
有人可以帮我解决这个问题吗?
谢谢
答案 0 :(得分:0)
请尝试在tablayout中使用“layout_marginTop = -8dp”。一个简单的解决方法。