簡體   English   中英

協調器布局和工具欄問題

[英]Issue with coordinator layout and toolbar

我正在做一個布局,希望在狀態欄后面繪制我的圖像。 我為此使用協調器布局,但是遇到了一個奇怪的問題。 當我使用下面給出的代碼時,我能夠實現這一目標

<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">

<ImageView
    android:id="@+id/album_art_playing"
    android:layout_width="match_parent"
    android:layout_height="360dp"
    android:fitsSystemWindows="true"/>

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true"/>
.....
</android.support.design.widget.CoordinatorLayout>

但是,當我將工具欄視圖移到圖像視圖上方時,我得到了這個 ,布局文件如下所示:

<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.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true"/>

<ImageView
    android:id="@+id/album_art_playing"
    android:layout_width="match_parent"
    android:layout_height="360dp"
    android:fitsSystemWindows="true"/>
....
</android.support.design.widget.CoordinatorLayout>

我無法理解為什么將工具欄窗口小部件移到圖像視圖上方會更改圖像視圖的行為,並且圖像未繪制在狀態欄后面。 我怎么能做到這一點。 我希望將我的圖像顯示在狀態欄的后面,但也希望顯示我的工具欄標題和圖標,而目前為止還沒有。

你是對的,

可能與圖像視圖重疊。

因為CoordinatorLayoutCoordinatorLayout android 文檔擴展了FrameLayout

CoordinatorLayout是功能強大的FrameLayout。

因此,它繼承了FrameLayout所有屬性,因此無論何時將視圖放置在另一個視圖之后,它都會與該視圖重疊。

現在出現了主要問題, 當您更改工具欄的順序時,為什么白色/灰色狀態欄可見?

這是因為,如果您在主題中使用“ follow”,則從棒棒糖或更高版本的系統可以繪制半透明的狀態欄(如果您不使用此功能,則該功能將無效)

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

所以在您的第一張圖片中,它顯示為灰色,因為您尚未定義工具欄的背景色(它僅考慮其下方的視圖,在這種情況下,該工具欄位於其下方),只需更改工具欄的顏色變成粉紅色,它將顯示這樣的預覽

彩色工具欄

我認為,當您更改工具欄的顏色時,您會明白的。

萬一您需要透明的工具欄,則必須為工具欄設置100%的透明背景色,並確保設置

在活動的OnCreate中:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

並在您的主題中:

<item name="android:statusBarColor">@android:color/transparent</item>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM