【问题标题】:ImageView not going behind the status bar in collapsing toolbarImageView 不会在折叠工具栏中的状态栏后面
【发布时间】:2016-09-25 17:53:31
【问题描述】:

我试图将图像视图放在折叠工具栏的状态栏后面,并尝试了许多解决方案,它位于状态栏后面,但在声明中它从状态栏下方开始,但在滚动时它位于后面。我该如何解决这个问题,这是 xml 文件(它是活动中的片段)

片段 XML:

<?xml version="1.0" encoding="utf-8"?>
<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/fragment_detail_app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/fragment_detail_collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:statusBarScrim="@android:color/transparent"
            app:theme="@style/Theme.AppCompat.NoActionBar">

            <com.android.volley.toolbox.NetworkImageView
                android:id="@+id/fragment_detail_collapsing_toolbar_image_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/fragment_detail_toolbar"
                android:layout_width="match_parent"
                android:layout_height="120dp"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:titleTextColor="@android:color/white">
            </android.support.v7.widget.Toolbar>

        </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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        </LinearLayout>

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

    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/fragment_detail_anchor_image"
        android:layout_width="96dp"
        android:layout_height="144dp"
        android:layout_margin="40dp"
        android:background="@android:color/white"
        app:layout_anchor="@id/fragment_detail_app_bar_layout"
        app:layout_anchorGravity="bottom"
        android:scaleType="fitXY"
        android:elevation="8dp"/>
</android.support.design.widget.CoordinatorLayout>

活动 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/movie_detail_fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    tools:context="app.com.thetechnocafe.moviesnow.MovieDetailActivity">

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

SCREENSHOT

【问题讨论】:

标签: android


【解决方案1】:

解决了。来自网络的图像具有不同的比例,我发现的一件事是,如果图像不适合 res 放在状态栏后面,那么它会自动适合状态栏下方。我所要做的就是在 NetworkImageView 中设置 android:scaleY="1.2" 以将其推送到状态栏中。

【讨论】:

  • 太棒了,帮了很多忙。
【解决方案2】:

在具有 API 21+ 的设备上,您可以使用使状态栏半透明的自定义主题。

<style name="AppTheme.NoActionBar.NoStatusBar">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

将此样式添加到values-v21 文件夹内的文件中,并在您的AndroidManifest.xml 中设置Activty 主题,如下所示:

<activity
   android:name=".activity.AboutActivity"
   android:theme="@style/AppTheme.NoActionBar.NoStatusBar" />

还有一件事。我认为您还需要将android:fitsSystemWindows="true" 添加到NetworkImageView

【讨论】:

  • 您正在测试的设备或模拟器是什么 API 级别?你能发布清单和样式文件吗?
  • 23 级,moto x 风格
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-10
相关资源
最近更新 更多