Imageview没有应用fitSystemWindows

时间:2016-01-20 18:45:38

标签: android android-layout android-toolbar android-collapsingtoolbarlayout

我需要将图像显示在状态栏下方(状态栏必须是透明的,不知道如何),但我无法使其工作,我尝试了很多布局样本。
这是我的xml布局:

<RelativeLayout 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"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.FullScreenPlayer">

<com.intaj.sawt.customviews.SquareImageView
    android:id="@+id/imgViewCover"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:scaleType="centerCrop"
    android:src="@drawable/cover_holder" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/imgViewCover"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/full_screen_player_bg"
        android:orientation="vertical"
        android:padding="5dp">

        <TextView
            android:id="@+id/txtSongTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textAppearance="@android:style/TextAppearance.Medium"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/txtArtistName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textAppearance="@android:style/TextAppearance.Medium" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp">

        <TextView
            android:id="@+id/startText"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:gravity="center_vertical"
            android:maxLines="1"
            android:textColor="@android:color/white" />

        <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_toEndOf="@+id/startText"
            android:layout_toLeftOf="@+id/endText"
            android:layout_toRightOf="@+id/startText"
            android:layout_toStartOf="@+id/endText" />

        <TextView
            android:id="@+id/endText"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:gravity="center_vertical"
            android:maxLines="1"
            android:textColor="@android:color/white" />

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/layoutPlaybackControls"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="16dp"
        android:paddingRight="16dp">

        <ImageView
            android:id="@+id/repeat"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_action_repeat"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/prev"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_skip_previous_white_48dp"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/playPause"
            android:layout_width="0dp"
            android:layout_height="70dp"
            android:layout_weight="1"
            android:src="@drawable/ic_play_arrow_white_48dp"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/next"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_skip_next_white_48dp"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/shuffle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_action_shuffle"
            android:tint="@color/colorAccent" />

    </LinearLayout>

</LinearLayout>

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_collapseMode="pin"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<com.pnikosis.materialishprogress.ProgressWheel
    android:id="@+id/progressBar"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:visibility="invisible"
    wheel:matProg_barColor="@color/colorAccentSettings"
    wheel:matProg_progressIndeterminate="true" />

这就是结果:
如您所见,状态栏不会透明或图​​像不在其下方。

enter image description here

我发布我的风格:

styles.xml

<style name="AppTheme" parent="AppTheme.Light" />
<!--<style name="AppThemeDark" parent="AppTheme.Dark" />-->

<style name="AppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar">
    <!--light-->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/textPrimaryColor</item>
    <item name="android:textColorSecondary">@color/colorPrimaryDark</item>
    <item name="android:windowBackground">@color/windowBackground</item>
</style>

styles.xml(v21)

 <style name="AppTheme" parent="AppTheme.Light">
    <item name="android:windowTranslucentStatus">true</item>
    <!--<item name="android:statusBarColor">@android:color/transparent</item>-->
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>

请帮助!!

1 个答案:

答案 0 :(得分:2)

  

试试这个

  <RelativeLayout 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"
       xmlns:wheel="http://schemas.android.com/apk/res-auto"
       android:id="@+id/rootLayout"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:fitsSystemWindows="true"
       tools:context=".activities.FullScreenPlayer">

 <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_collapseMode="pin"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<com.intaj.sawt.customviews.SquareImageView
    android:id="@+id/imgViewCover"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:layout_below="@id/toolbar"
    android:scaleType="centerCrop"
    android:src="@drawable/cover_holder" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/imgViewCover"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/full_screen_player_bg"
        android:orientation="vertical"
        android:padding="5dp" >

        <TextView
            android:id="@+id/txtSongTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textAppearance="@android:style/TextAppearance.Medium"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/txtArtistName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textAppearance="@android:style/TextAppearance.Medium" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp" >

        <TextView
            android:id="@+id/startText"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:gravity="center_vertical"
            android:maxLines="1"
            android:textColor="@android:color/white" />

        <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_gravity="center"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_toEndOf="@+id/startText"
            android:layout_toLeftOf="@+id/endText"
            android:layout_toRightOf="@+id/startText"
            android:layout_toStartOf="@+id/endText" />

        <TextView
            android:id="@+id/endText"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:gravity="center_vertical"
            android:maxLines="1"
            android:textColor="@android:color/white" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/layoutPlaybackControls"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="16dp"
        android:paddingRight="16dp" >

        <ImageView
            android:id="@+id/repeat"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_action_repeat"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/prev"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_skip_previous_white_48dp"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/playPause"
            android:layout_width="0dp"
            android:layout_height="70dp"
            android:layout_weight="1"
            android:src="@drawable/ic_play_arrow_white_48dp"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/next"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_skip_next_white_48dp"
            android:tint="@color/colorAccent" />

        <ImageView
            android:id="@+id/shuffle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_action_shuffle"
            android:tint="@color/colorAccent" />
    </LinearLayout>
</LinearLayout>

<com.pnikosis.materialishprogress.ProgressWheel
    android:id="@+id/progressBar"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:visibility="invisible"
    wheel:matProg_barColor="@color/colorAccentSettings"
    wheel:matProg_progressIndeterminate="true" />

  </RelativeLayout>