PopupWindow
来源:互联网 发布:p2p网贷系统源码由来 编辑:程序博客网 时间:2024/06/06 02:04
对于PopupWindow的使用,感觉不是很重要,但还是记下来把,免得以后用到。
其主要实现的是点击一个按钮另外一个布局中的三个按钮,分别是“确定”,”跳转“和”取消“。然后当点击取消的时候,又缩回原来的一个按钮
MainActivity:
package com.example.day_0921_02;import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.view.View;import android.widget.ImageButton;import android.widget.PopupWindow;public class MainActivity extends Activity {private ImageButton imageButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageButton = (ImageButton) findViewById(R.id.imageButton);View root = getLayoutInflater().inflate(R.layout.popu_layout, null);final PopupWindow pWindow = new PopupWindow(root, 200, 200);imageButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {pWindow.showAsDropDown(v);pWindow.showAtLocation(imageButton, Gravity.CENTER, 20, 20);}});root.findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {pWindow.dismiss();}});}}两个布局文件也发一下吧。
activity_main.xml:
<RelativeLayout 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" > <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /></RelativeLayout>
第二个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:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳转"/> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消"/></LinearLayout>
0 0
- popupwindow
- popupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- popupwindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- popupwindow
- popupwindow
- PopupWindow
- Java 多线程常用概念
- leetcode-101-Symmetric Tree
- poj--1256
- 黑马程序员_java 操作文件的扩展,制作excel表格
- CYC-集合视图 UICollectionView的简单使用
- PopupWindow
- 工业设计如何从零开始学手绘
- -Java语法基础(概述)
- 浅谈iOS中MVVM的架构与团队协作
- scanner 死循环问题
- 2_Add Two Number
- 快手之家(aardio.net) - 构思
- android2.3平台上web页面(html5中使用frame)不能滑动、不允许缩放的解决方法
- 嵌入式硬件及接口开发实践