Android LinearLayout整个布局设置不可点击
1,activity的xml布局(布局中有个Button按钮,点击按钮弹出一个popupwindow )
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher_background"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:onClick="click"
android:textSize="30sp"
android:text="弹窗Popupwindow"/>
</LinearLayout>
2,上图中有白色背景的popupwindow 的xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/ll_popup">
<LinearLayout
android:id="@+id/ll_popup_content"
android:layout_width="600dp"
android:layout_height="400dp"
android:gravity="center"
android:background="@android:color/white">
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="250dp"
android:padding="10dp"
android:src="@drawable/fengjing"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="250dp"
android:padding="10dp"
android:src="@drawable/small"/>
</LinearLayout>
</LinearLayout>
3,MainActivity的代码实现:
public class MainActivity extends AppCompatActivity {
private View pop;
private LinearLayout ll_popup,ll_popup_content;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pop = View.inflate(this, R.layout.popupwindow_test, null);
ll_popup = pop.findViewById(R.id.ll_popup);
ll_popup_content = pop.findViewById(R.id.ll_popup_content);
ll_popup_content.setOnClickListener(null);//Linearloyout就不可点击了
}
public void click(View view) {
final PopupWindow popupWindow = new PopupWindow(pop, MATCH_PARENT, MATCH_PARENT);
ll_popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.TOP,0,0);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
//完全沉浸式
super.onWindowFocusChanged(hasFocus);
if (hasFocus && Build.VERSION.SDK_INT >= 19) {
View decorView = getWindow().getDecorView(http://www.my516.com);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
}
---------------------
最新文章
- ZOJ 3805 (树形DP)
- java中 set,list,array(集合与数组)相互转换
- LAMP网站架构方案分析
- 用户浏览器关闭cookie处理方法
- how tomcat works 读书笔记四 tomcat的默认连接器
- Java凝视Annotation
- HLJU 1223: 寻找区间和 (交替推进法)
- PHP die与exit的区别
- CUDA学习,环境配置和简单例子
- 2019年4月zstu月赛A: 我不会做
- Confluence 6 编辑站点欢迎消息
- tortoiseSVN版本合并(merge)
- WPF 创建自定义控件及自定义事件
- layui动态options
- JavaScript -- Document-open
- 【原创】when.js2.7.1源码解析
- 012-Go ORM框架之Gorm测试
- Python-Image 基本的图像处理操作
- 17.并发容器之ThreadLocal
- 【Leetcode】【Medium】Linked List Cycle