在andriod里实现透明遮罩效果

来源:互联网 发布:用js做框架 编辑:程序博客网 时间:2024/04/30 14:56
一,在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
原创粉丝点击