ImageView不会在折叠工具栏中的状态栏后面
问题描述:
我试图在折叠工具栏中将状态栏背后的图像视图,并尝试了很多解决方案,它在状态栏后面,但在状态栏下方开始说明它,但在滚动它后面。我怎样才能解决这个问题,这里是XML文件(它是一个活动中的片段)ImageView不会在折叠工具栏中的状态栏后面
片段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>
答
把它解决了。来自网络的图像具有不同的比例,我发现的一件事是,如果图像不适合状态栏后面的资源,它会自动适应状态栏。我只需要在NetworkImageView中设置android:scaleY="1.2"
将其推入状态栏。
+0
真棒马恩,帮助了很多。 –
答
在使用API 21+的设备可以使用使状态栏变为半透明的自定义主题。
<style name="AppTheme.NoActionBar.NoStatusBar">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
这种风格在你AndroidManifest.xml
添加到文件夹values-v21
内并设置Activty主题是这样的:
<activity
android:name=".activity.AboutActivity"
android:theme="@style/AppTheme.NoActionBar.NoStatusBar" />
还有一件事。我认为您还需要将android:fitsSystemWindows="true"
添加到NetworkImageView
。
见http://stackoverflow.com/questions/33668668/coordinatorlayout-not-drawing-behind-status-bar-even-with-windowtranslucentstatu – Philipp