您的位置:首页 > 移动开发 > Android开发

在andriod里实现透明遮罩效果

2014-01-07 14:37 190 查看
一,在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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息