首页 文章

半透明层顶部的不透明层

提问于
浏览
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>

如何在保持顶层完全不透明的同时使这个中间层半透明?谢谢你的帮助!

1 回答

  • 0

    您好,在drawable文件夹中创建semitransperent.xml

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

    注意根据您的要求,您需要更改笔划,渐变,角落 .

    在xml代码中添加以下行:

    android:background="@drawable/semitransperent"
    

相关问题