Android:半透明叠加?

时间:2015-10-14 22:23:59

标签: android android-layout android-xml

我想要一个半透明的'覆盖在布局之上。我想保持下面的布局不变,只需在顶部添加此视图。

目前我正在使用带有背景的imageView设置为包含透明色的可绘制文件:

  <?xml version="1.0" encoding="UTF-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#80FF0000"/>
    <stroke android:width="3dip"
        android:color="#80FF0000" />
    <corners android:radius="5dip"/>
    <padding android:left="2dip" android:top="2dip" android:right="2dip" android:bottom="2dip" />
</shape>

和布局:

 <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageView10"
    android:background="@drawable/building_block_trans_red"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

然而......它在Android Studio中运行良好,并在布局顶部显示半透明叠加层,但是当我将其加载到手机上时没有叠加?

请引导我到我错过的地方?

编辑1: 完整项目的xml文件。

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/OdasRelativeLayoutNoData"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/building_block"
    android:padding="3dp"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="105dp"
        android:layout_height="fill_parent"
        android:id="@+id/OdasSideBarLayoutNoData"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/building_block_light"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:id="@+id/linearLayout16"
            android:layout_alignParentLeft="true">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="bottom|center_horizontal"
                android:layout_gravity="bottom|center_horizontal"
                android:id="@+id/textView34"
                android:text="@string/odasBuoy"
                android:background="@drawable/tidal_header"
                android:textSize="25dp"
                android:textColor="#ffffff"
                android:textStyle="bold"
                android:typeface="sans"
                tools:ignore="SpUsage" />

            <ImageView
                android:id="@+id/icon2"
                android:layout_width="90dp"
                android:layout_height="75dp"
                android:layout_gravity="top|center_horizontal"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:background="@drawable/ic_odas1" />

        </LinearLayout>

    </RelativeLayout>

    <!-- AutoResize Class handles text size so it fills the available space -->
    <com.prowapps.seaport.AutoResizeTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start|fill"
        android:text="@string/OdasInfo"
        android:typeface="sans"
        android:textColor="#ffffff"
        android:layout_marginLeft="5dp"
        android:id="@+id/textView35"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/OdasSideBarLayoutNoData"
        android:layout_alignParentRight="true"
        android:padding="2dp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/building_block_red" />

</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

您也可以简单地使用视图而不是ImageView和Shapefile。

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#80FF0000"/>

此外,由于您的视图覆盖整个屏幕,因此您不需要layout_align语句。

答案 1 :(得分:0)

通过我的library,您可以创建具有自定义透明级别的叠加层。 gif预览-

enter image description here

相关问题