android遮罩层
16lz
2021-01-24
android遮罩层 1.建立FrameLayout,因为该布局方式只显示下层内容,如:
1<FrameLayout
2xmlns:android="http://schemas.android.com/apk/res/android"
3android:layout_width="match_parent"
4android:layout_height="fill_parent">
5<LinearLayout
6android:layout_width="fill_parent"
7android:layout_height="fill_parent"
8android:orientation="vertical"
9android:id="@+id/main"
10android:background="@color/white"
11>
12<LinearLayout
13android:layout_width="fill_parent"
14android:layout_height="wrap_content"
15>
16<GridView
17android:id="@+id/gridview_send"
18android:layout_width="fill_parent"
19android:layout_height="fill_parent"
20android:layout_marginLeft="20dp"
21android:layout_marginTop="40dp"
22android:listSelector="@color/bule_overlay"
23android:numColumns="4">
24</GridView>
25</LinearLayout>
26<ImageView
27android:layout_width="fill_parent"
28android:layout_height="wrap_content"
29android:src="@drawable/service_public_diver"
30android:layout_marginLeft="20dp"
31android:layout_marginRight="20dp"
32android:layout_marginTop="40px"
33/>
34<EditText
35android:id="@+id/issueContent"
36android:layout_width="fill_parent"
37android:layout_height="wrap_content"
38android:minLines="4"
39android:gravity="top"
40android:layout_marginLeft="20dp"
41android:layout_marginRight="20dp"
42android:layout_marginTop="30px"
43android:textColor="#e3e3e3"
44android:hint="请输入内容"
45android:background="@null"
46android:textSize="46px"/>
47<ImageView
48android:layout_width="fill_parent"
49android:layout_height="wrap_content"
50android:src="@drawable/service_public_diver"
51android:layout_marginLeft="20dp"
52android:layout_marginRight="20dp"
53android:layout_marginTop="40dp"
54/>
55</LinearLayout>
56<LinearLayout
57android:id="@+id/layerMask"
58android:layout_width="fill_parent"
59android:layout_height="fill_parent"
60android:orientation="vertical"
61android:background="@drawable/common_title_back"
62android:visibility="gone">
63</LinearLayout>
64</FrameLayout>
2.在layerMasK中添加view内容
private LinearLayout layerMask;//遮罩层
layerMask = (LinearLayout)contentView.findViewById(R.id.layerMask);
addInnerLayout(R.layout.fragment_takephotoathand_layer,layerMask);
//设置点击不退出遮罩层 layerMask.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { return true; } });
private void addInnerLayout(int layoutResID,LinearLayout view){ LayoutInflater inflater = (LayoutInflater) ((Activity) mContext).getLayoutInflater(); View CurView = inflater.inflate(layoutResID, null); LinearLayout.LayoutParams lineparam = new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); view.addView(CurView,lineparam); }
3.控制显示
layerMask.setVisibility(View.VISIBLE);
1<FrameLayout
2xmlns:android="http://schemas.android.com/apk/res/android"
3android:layout_width="match_parent"
4android:layout_height="fill_parent">
5<LinearLayout
6android:layout_width="fill_parent"
7android:layout_height="fill_parent"
8android:orientation="vertical"
9android:id="@+id/main"
10android:background="@color/white"
11>
12<LinearLayout
13android:layout_width="fill_parent"
14android:layout_height="wrap_content"
15>
16<GridView
17android:id="@+id/gridview_send"
18android:layout_width="fill_parent"
19android:layout_height="fill_parent"
20android:layout_marginLeft="20dp"
21android:layout_marginTop="40dp"
22android:listSelector="@color/bule_overlay"
23android:numColumns="4">
24</GridView>
25</LinearLayout>
26<ImageView
27android:layout_width="fill_parent"
28android:layout_height="wrap_content"
29android:src="@drawable/service_public_diver"
30android:layout_marginLeft="20dp"
31android:layout_marginRight="20dp"
32android:layout_marginTop="40px"
33/>
34<EditText
35android:id="@+id/issueContent"
36android:layout_width="fill_parent"
37android:layout_height="wrap_content"
38android:minLines="4"
39android:gravity="top"
40android:layout_marginLeft="20dp"
41android:layout_marginRight="20dp"
42android:layout_marginTop="30px"
43android:textColor="#e3e3e3"
44android:hint="请输入内容"
45android:background="@null"
46android:textSize="46px"/>
47<ImageView
48android:layout_width="fill_parent"
49android:layout_height="wrap_content"
50android:src="@drawable/service_public_diver"
51android:layout_marginLeft="20dp"
52android:layout_marginRight="20dp"
53android:layout_marginTop="40dp"
54/>
55</LinearLayout>
56<LinearLayout
57android:id="@+id/layerMask"
58android:layout_width="fill_parent"
59android:layout_height="fill_parent"
60android:orientation="vertical"
61android:background="@drawable/common_title_back"
62android:visibility="gone">
63</LinearLayout>
64</FrameLayout>
2.在layerMasK中添加view内容
private LinearLayout layerMask;//遮罩层
layerMask = (LinearLayout)contentView.findViewById(R.id.layerMask);
addInnerLayout(R.layout.fragment_takephotoathand_layer,layerMask);
//设置点击不退出遮罩层 layerMask.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { return true; } });
private void addInnerLayout(int layoutResID,LinearLayout view){ LayoutInflater inflater = (LayoutInflater) ((Activity) mContext).getLayoutInflater(); View CurView = inflater.inflate(layoutResID, null); LinearLayout.LayoutParams lineparam = new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); view.addView(CurView,lineparam); }
3.控制显示
layerMask.setVisibility(View.VISIBLE);
更多相关文章
- 通过API级别进行文档内容过滤
- 数组资源(arrays)的使用
- Android之代码创建布局
- android 解决输入法键盘遮盖布局问题
- layout 向下一级传点击事件 descendantFocusability
- 简单实现RecyclerView版本的竖向翻页效果
- Android(安卓)10 获取剪切板内容
- Android(安卓)处理空列表的方法(必看篇)
- Android(安卓)App快速启动