我的 FrameLayout (抽屉布局中的容器)有问题。 FrameLayout的高度超过了屏幕高度(在底部的android默认菜单按钮下方)。
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/navContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
我的第一次尝试是设置一个android:layout_marginBottom="?attr/actionBarSize"
在框架布局中。这解决了在没有垂直可滚动内容的情况下具有“固定”高度的不可滚动视图的解决方案(就像通常的relativelayoutmatch_parent
高度)。将组件与父级底部对齐(android:layout_alignParentBottom="true"
) 导致元素仍然可见。在 Android Studio Preview 中,可见高度不超过。
However, this marginBotton-fix introduces a new problem for fragments whose root view is scrollable (like a RecyclerView). For these views when scrolling down the bottom margin will become visible in a white bar (in case white is the background color). This seams reasonable, as for those views the nested scrolling feature will slide out the toolbar
tl;dr我通过应用解决了这个问题?attr/actionBarSize
作为框架布局内显示的不可滚动片段的下边距。在此之前我将工具栏的高度设置为?attr/actionBarSize
.
活动布置:
<android.support.design.widget.AppBarLayout
android:id="@+id/navContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
片段布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize"
android:orientation="vertical">
<!-- Further stuff here -->
<TextView android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
</LinearLayout>
我现在面临的唯一缺点是创建片段布局时 Android Studio 的预览器中显示的空白。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)