2015-10-08 9 views
0

我爲一個活動創建了此佈局文件@+id/activity_play_panel將狀態欄顏色設置爲透明使活動中的其他視圖透明

<LinearLayout  
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/activity_play_panel" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

tools:context="com.example.michael.musicplayer.PlayPanel"> 

<View 
    android:id="@+id/rectangle_at_the_top" 
    android:layout_width="match_parent" 
    android:layout_height="10dp" 
    android:background="#00FFFF"/> 

<View 
    android:id="@+id/rectangle_at_the_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000"/> 

我加入下面的Java代碼,使黑條下方的狀態欄@+id/activity_play_panel tranparent。

ColorDrawable colorDrawable = new ColorDrawable(Color.TRANSPARENT); 
    getWindow().setBackgroundDrawable(colorDrawable); 
    getWindow().setStatusBarColor(Color.TRANSPARENT); 

然而,經過予添加代碼以使狀態欄透明,在@+id/activity_play_panel第二視圖也變成透明的。

如果我顛倒了視圖的順序,那麼我可以看到第二個視圖,但不是第一個視圖,例如

<!-- Not transparent--> 

<View 
    android:id="@+id/rectangle_at_the_top" 
    android:layout_width="match_parent" 
    android:layout_height="10dp" 
    android:background="#00FFFF"/> 

<!-- Transparent--> 

<View 
    android:id="@+id/rectangle_at_the_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000"/> 

或者對反轉

<!-- Not transparent--> 

<View 
    android:id="@+id/rectangle_at_the_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000"/> 

<!-- Transparent--> 

<View 
    android:id="@+id/rectangle_at_the_top" 
    android:layout_width="match_parent" 
    android:layout_height="10dp" 
    android:background="#00FFFF"/> 
+0

就像一句話,我注意到你沒有指定默認爲水平的方向 –

回答

0

用於線性佈局的默認取向是水平的。

我只需將父線性佈局設置爲垂直方向。

android:orientation="vertical" 
0

我固定它^^ 了,因爲你沒有match_parent在rectangle_at_the_bottom高度值! 更改爲:

<View 
android:id="@+id/rectangle_at_the_bottom" 
android:layout_width="match_parent" 
android:layout_height="10dp" 
android:background="#000000"/>