Android 安卓导航栏,包括viewpager内容
我无法阻止系统导航栏掩盖我的内容 我被滚动到recyclerview的最底部,但它隐藏在导航栏后面。这是我的XML布局Android 安卓导航栏,包括viewpager内容,android,android-fragments,android-viewpager,navigationbar,Android,Android Fragments,Android Viewpager,Navigationbar,我无法阻止系统导航栏掩盖我的内容 我被滚动到recyclerview的最底部,但它隐藏在导航栏后面。这是我的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/root" and
<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/root"
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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include layout="@layout/toolbar"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:fitsSystemWindows="true"
android:id="@+id/viewpager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.melnykov.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
app:fab_colorNormal="@color/accent"
app:fab_colorPressed="@color/accent_dark" />
这是您在图片中看到的片段布局
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</FrameLayout>
我试着将android:fitsystemwindows=“true”添加到每一个布局中,但没有成功。其他线程提到添加根据条计算的边距,但这似乎不是正确的解决方案。我直接从谷歌的CheesSquare应用程序演示appbarlayout中获取了这个布局,这个布局看起来很好用。尝试替换你的gradle依赖项
com.android.support:recyclerview-v7:22.0.+
与
或
(不确定这是正确的表示法)问题在于使用
AppBarLayout
。CoordinatorLayout
作为强大的FrameLayout
引入,它基于定义的行为
提供了漂亮的动画。如果我们想添加某种滚动
动画,如折叠工具栏
等,那么我们必须用AppBarLayout
包装工具栏
,但是当我们想在协调布局
中放置静态内容时,比如您的ViewPager
,那么我们根本不需要使用AppBarLayout
:
activity_main.xml:
content_main.xml:
Viewpager的片段根视图必须是
RecyclerView
或NestedScrollView
FrameLayout
不支持CoordinatorLayout
的滚动行为,这就是它不能正常工作的原因
如何修复viewpager的片段布局:不要将
RecyclerView
包装在FrameLayout
内。而是在根目录下声明RecyclerView
。您还可以在RecyclerView
上设置padding=“8dp”
,只需使用android:cliptoppadding=“false”
,我就知道了。在我的特定情况下,我的每个片段都管理自己的工具栏实例。我在片段的onViewCreated()方法中调用setSupportActionBar()。将此功能移动到onCreateView()解决了此问题
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_my_account, container, false);
setupToolbar((Toolbar) view.findViewById(R.id.toolbar));
return view;
}
private void setupToolbar(Toolbar toolbar) {
toolbarController.registerToolbar(toolbar);
toolbarController.setActivityTitle("My Account");
}
(registerToolbar()在宿主活动内调用setSupportActionBar()
希望这对大家都有帮助 转到style.xml并删除这两项,或将其“true”值设置为“false”
true
真的
在我的例子中,通过删除这两个主题样式值,问题得到了解决。只需将边距底部添加到
查看页面
即可为我解决问题
以下是我的activity_main.xml中的代码
<android.support.v4.view.ViewPager
android:id="@+id/main_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="55dp"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
将ViewPager包装到ConstraintLayout中,然后设置为您的ViewPager:
app:layout_constraintBottom_toBottomOf="parent"
应该可以不,活动不是全屏的。这是一项标准活动,没有特殊标志或任何东西。在您的RecyclerView或root视图中添加适当的边距。这应该可以解决你的问题。这是一个很好的解决办法,但我正在努力找到问题的根源。这似乎不是正常的行为。我也有一个确切的问题:(你解决过这个问题吗?我认为你根本不应该添加marginTop。要获得更灵活的解决方案-使用选项卡处理应用程序栏布局或折叠工具栏布局,你应该将工具栏包装在appbarlayout中,并使用app:layout\u行为=“@string/appbar\u scrolling\u view\u behavior”我在CoordinatorLayout内部使用Srcollview,面对类似的问题,能够解决这是什么工具栏控制器?哦,天哪,这真的不是小事
<RelativeLayout
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:background="#A1D490"
// Remember CoordinatorLayout is a kind of FrameLayout,
// so we have to provide top margin to make Toolbar visible
android:layout_marginTop="?attr/actionBarSize"
tools:context="com.mydemoci.MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@color/colorAccent"
android:text="Hello World"
android:textSize="30sp"/>
</RelativeLayout>
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_my_account, container, false);
setupToolbar((Toolbar) view.findViewById(R.id.toolbar));
return view;
}
private void setupToolbar(Toolbar toolbar) {
toolbarController.registerToolbar(toolbar);
toolbarController.setActivityTitle("My Account");
}
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<android.support.v4.view.ViewPager
android:id="@+id/main_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="55dp"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
app:layout_constraintBottom_toBottomOf="parent"