当前位置:网站首页>使用popupwindow創建对话框风格的窗口
使用popupwindow創建对话框风格的窗口
2022-07-07 15:40:00 【XLMN】
使用popupwindow創建对话框风格的窗口
public class MainActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popupwindow);
// 加载r.layout.popup对应的布局文件
View root = this.getLayoutInflater().inflate(R.layout.popup, null);
//創建popupwindow对象
final PopupWindow pw = new PopupWindow(root, 1560, 1720);
Button bt = findViewById(R.id.button2);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 以下拉的方式显示
pw.showAsDropDown(v);
//将popupwindow显示在指定的位置
pw.showAtLocation(findViewById(R.id.button2), Gravity.CENTER, 20, 20);
}
});
//获取popupwindow中关闭按钮
root.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//关闭popupwindow
pw.dismiss();
}
});
}
}
<ImageView
android:layout_width="wrap_content"
android:layout_height="560dp"
android:src="@drawable/mia1" />
<Button
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="关闭" />
<?xml version="1.0" encoding="utf-8"?> <Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="弹出popop窗口" />
边栏推荐
- LeetCode 1774. The dessert cost closest to the target price is one question per day
- User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
- From Devops to mlops: how do it tools evolve to AI tools?
- Problems encountered in Jenkins' release of H5 developed by uniapp
- 【网络攻防原理与技术】第3章:网络侦察技术
- Smart logistics platform: make overseas warehouses smarter
- LeetCode 535(C#)
- 第2章搭建CRM项目开发环境(数据库设计)
- 麒麟信安云平台全新升级!
- centos7安装mysql笔记
猜你喜欢
【视频/音频数据处理】上海道宁为您带来Elecard下载、试用、教程
Sator推出Web3游戏“Satorspace” ,并上线Huobi
【TPM2.0原理及应用指南】 5、7、8章
麒麟信安加入宁夏商用密码协会
Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
第3章业务功能开发(实现记住账号密码)
第2章搭建CRM项目开发环境(数据库设计)
【信息安全法律法规】复习篇
管理VDI的几个最佳实践
【TPM2.0原理及应用指南】 12、13、14章
随机推荐
测试用例管理工具推荐
Smart logistics platform: make overseas warehouses smarter
科普达人丨一文弄懂什么是云计算?
redis主从、哨兵主备切换搭建一步一步图解实现
MySQL usage notes 1
centos7安装mysql笔记
Repair method of firewall system crash and file loss, material cost 0 yuan
【可信计算】第十一次课:TPM密码资源管理(三) NV索引与PCR
管理VDI的几个最佳实践
【TPM2.0原理及应用指南】 12、13、14章
With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
Several best practices for managing VDI
Skimage learning (1)
SlashData开发者工具榜首等你而定!!!
DevOps 的运营和商业利益指南
Number of exchanges in the 9th Blue Bridge Cup finals
Sator launched Web3 game "satorspace" and launched hoobi
LeetCode 890(C#)
How to implement safety practice in software development stage
第3章业务功能开发(实现记住账号密码)