【发布时间】:2018-01-05 19:37:59
【问题描述】:
我有一个FrameLayout,其中包含用于背景的ImageView 和ScrollView 中的LinearLayout,以显示我需要的所有视图。简化代码如下所示,用于我的Fragment
<FrameLayout 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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ink"
android:scaleType="center"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linear_layout_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</FrameLayout>
这个片段放在我的activity_main.xml 的FrameLayout 中,看起来像这样
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
</FrameLayout>
当项目高度总和大于屏幕高度时,ScrollView 启动,我可以像预期的那样滚动 LinearLayout 内的所有项目。
问题是当我滚动到LinearLayout 的顶部时,最上面的视图隐藏在状态栏后面,如下图所示:
我正在寻找的行为是这样的:
我怎样才能完成第二张图片中显示的结果?
我的styles.xml如下
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
【问题讨论】:
-
您能否编辑您的问题以包含此活动使用的主题的样式定义?
-
它在实际设备或模拟器上能正常工作吗?
-
嗯...不是我期望看到的。以防万一,将
android:fitsSystemWindows="true"添加到根框架布局可以解决问题吗? -
我实际上已经有
android:fitsSystemWindows="true"到我的根FrameLayout。当我在实际设备上运行它时,会发生与预览相同的事情,除非我将设备旋转到横向视图时,更大的部分隐藏在设备顶部之后,我无法向下滚动。另一方面,底部有额外的填充,可能与顶部的尺寸相同
标签: android android-layout statusbar android-scrollview