内容位于应用栏布局下方

3
在我的应用中,内容被隐藏在appbarlayout下面。我不希望出现这种情况!
安卓23预览版

enter image description here

ANDROID 21 - 在设备上测试

enter image description here

ANDROID 21 - 设备上的测试内容隐藏在工具栏下

enter image description here

虽然我的内容向下滚动如预期,但当它向上滚动时,内容会隐藏在工具栏下面。我还上传了 Android 23 预览版,因为实际上工具栏与状态栏之间是顶部对齐的。在设备上工作时,如果预览正确,内容会向上移动到应该移动的位置。但工具栏视图在状态栏下面而不是在后面。我不知道问题出在哪里。
样式
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>

<style name="AppTheme.NoStatusBar" parent="AppTheme.NoActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>

更新

好的,我找到了解决方案。原来是很愚蠢的问题。只是我的scrollView因为最后一个获取焦点的子元素 - recycler view 而向下滚动了。 现在我设置了cardView的focusableInTouchMode="true",并将最后一个元素设为false。

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:fitsSystemWindows="true"
        android:fillViewport="true">

 <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="4dp"
        android:layout_margin="4dp"
        app:contentPaddingTop="24dp"
        android:focusableInTouchMode="true"/>

...
 <android.support.v7.widget.RecyclerView
       android:id="@+id/recycler_view_overbid_history"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:maxHeight="200dp"
       android:focusable="false"
       android:focusableInTouchMode="false"/>

android.support.v4.widget.NestedScrollView>

1个回答

1
我将与您分享部分编程代码,这是我的应用程序中有效的代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="240dp"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:expandedTitleMarginBottom="140dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.75">

            <ImageView
                android:id="@+id/store_detail_background"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop" />

            ...

        </FrameLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.v4.widget.NestedScrollView>

v21/styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@color/...</item>
    <item name="windowActionModeOverlay">true</item>
    ...
</style>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接