2017-07-07 39 views
-7

我想設計一個完全像下圖所示的佈局。我怎麼可以在android工作室透明背景?

當我把我的線性佈局alpha透明化時,它裏面的所有圖標也變得透明並且完全正常。但我想要一種方式來讓透明背景不是所有的項目!

我希望有一個透明的佈局是這樣的:

enter image description here

但我的佈局,這樣表示:

enter image description here

這裏是我的代碼:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="100dp" 
    android:background="@color/colorPrimary" 
    android:orientation="vertical" 
    android:alpha="0.5" 
    > 



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:alpha="1" 
     > 

     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333" 
      android:padding="10dp" 
      > 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333" 
      android:padding="10dp"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333" 
      android:padding="10dp"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
    </LinearLayout> 



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="1dip" 
      android:layout_height="fill_parent" 
      android:layout_weight="0.333"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@mipmap/consert" 
       android:layout_gravity="center_horizontal" 
       /> 

     </RelativeLayout> 
    </LinearLayout> 

</LinearLayout> 
+1

使背景透明的佈局,然後在tranparent部分設置您的圖標。而你的結果會讓你開心 –

+0

我認爲這是我所做的!你能告訴我如何在我的代碼中修復它嗎? tnx – Saeid

+1

在頂部的LinearLayout上,只需給它一個透明的背景顏色,比如說做一個#FF000000,這樣可以防止佈局小部件受到alpha屬性的影響。 –

回答

2

你如果你願意,可以嘗試這樣nt來調整透明度,改變我給出的#55000000的顏色,你可以改變任何你想要的alpha值(55)。如果你希望黑色的透明度,你可以使用#55FFFFFF

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/colorPrimary" 
       android:orientation="vertical" 
    > 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="100dp" 
     android:background="#55000000" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="3" 
      > 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 
     </LinearLayout> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="3" 
      > 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:padding="10dp" 
       > 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:background="@mipmap/ic_launcher" 
        /> 

      </RelativeLayout> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 
+0

tnx它工作正常:) – Saeid