Okn*_*Okn 10 height android matching android-framelayout
我的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>
Run Code Online (Sandbox Code Playgroud)
我的第一次尝试是android:layout_marginBottom="?attr/actionBarSize"在FrameLayout 设置一个.这解决了具有"固定"高度的不可滚动视图的解决方案,其中没有可垂直滚动的内容(如通常的具有match_parent高度的RelativeLayout ).将组件与父底部(android:layout_alignParentBottom="true")对齐会产生一个仍然可见的元素.在Android Studio的预览器中,可以看到不超过高度.
但是,此marginBotton-fix为其根视图可滚动的片段(如RecyclerView)引入了一个新问题.对于这些视图,当向下滚动时,底部边距将在白色条中可见(如果白色是背景颜色).这种接缝合理,对于那些视图,嵌套滚动功能将滑出工具栏

tl; dr我通过将?attr/actionBarSize底部边距应用于Framelayout内部显示的不可滚动片段来解决该问题.在此之前,我将工具栏的高度设置为?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>
Run Code Online (Sandbox Code Playgroud)
片段布局:
<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>
Run Code Online (Sandbox Code Playgroud)
我现在面临的唯一缺点是在创建片段布局时,Android Studio的预览器中会显示空白区域.
| 归档时间: |
|
| 查看次数: |
4885 次 |
| 最近记录: |