在andriod里实现透明遮罩效果

一,在android里实现遮罩效果的思路:
在aa里用bb把cc屏蔽掉(遮罩)。
二,实现过程以及原理:
1,使用FrameLayout的特性
整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置,
它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,
将前面的子元素部分和全部遮挡。

2,用ps制作就张透明图片,最好用android里的drawable让图片平铺 android:tileMode="repeat"   

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/zhezhao"
    android:tileMode="repeat"   

/>

3,使用View的addView(aa.addView(bb);)或者setVisibility(bb.setVisibility(0);)
如果你选择的是addView那么你要findViewById找到在什么地方实现遮罩;
如果你选择的是setVisibility那么你要findViewById找到用什么实现遮罩;

注意:aa一定是FrameLayout

三,参看Layout文件

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

    <TextView
        android:id="@+id/bb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <ImageView
        android:id="@+id/cc"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:src="@drawable/zhezhao2"
        android:visibility="gone" >
    </ImageView>

</FrameLayout>


God bless you

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值