2015-12-30 80 views
0

我有一個活動,按照我的意願進行佈置。當用戶點擊一個按鈕時,我顯示一個彈出式編輯文本框。我想在彈出的edittext和半透明的主層之間放置一箇中間層,以保持用戶的注意力集中在彈出窗口上。半透明層頂部的不透明層

所以我設置中間層的alpha值爲0.5。然而,即使我明確地將其alpha設置爲1.0,彈出層現在也呈現爲半透明。

<!-- this is the middle layer (I call it the 'curtain') --> 
<LinearLayout 
    android:id="@+id/log_entry_reply_container_curtain" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:alpha="0.5" 
    android:visibility="gone"> 

    <!-- this is the popup layer --> 
    <RelativeLayout 
     android:id="@+id/log_entry_reply_container" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:layout_gravity="center" 
     android:alpha="1.0" 
     style="@style/RoundedCornersView" > 

     <TextView 
      android:id="@+id/log_entry_tv_reply" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:textSize="22sp" 
      android:layout_marginBottom="5dp" 
      android:layout_alignParentTop="true" 
      android:text="@string/enter_reply"/> 

     <EditText 
      android:id="@+id/log_entry_reply_edittext" 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_below="@+id/log_entry_tv_reply" 
      android:layout_margin="5dp" 
      android:gravity="top"/> 

    </RelativeLayout> 
</LinearLayout> 

如何讓這個中間層半透明,同時仍然保持頂層完全不透明?謝謝你的幫助!

回答

0

喜在繪製文件夾

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <stroke android:width="2dp" /> 



    <gradient 
     android:angle="90" 
     android:endColor="#29000000" 
     android:startColor="#29000000" /> 

    <corners 
     android:bottomLeftRadius="7dp" 
     android:bottomRightRadius="7dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp" /> 

</shape> 

Note.Stroke,梯度創建semitransperent.xml,邊角按照您的要求,你需要改變。

加入線之下行XML代碼:

android:background="@drawable/semitransperent" 
+0

非常感謝這一點。我將此標記爲解決方案,因爲它可行。然而,對於任何可能使用這個標籤的人,我會指出''的主體不需要任何'',''或''標籤。我需要解決的所有原始問題都是簡單的'其中'cc'表示您希望應用於背景的任何Alpha值。感謝您的建議。它絕對有效! – Alex