王立平--PopupWindow
MainActivity.java
<span style="font-size:14px;">package com.main; import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow; public class MainActivity extends Activity { private static final String TAG = "MainActivity";
private Button button; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 显示 popupWindow
PopupWindow popupWindow = makePopupWindow(MainActivity.this);
int[] xy = new int[2];
button.getLocationOnScreen(xy);
popupWindow.showAtLocation(button, Gravity.RIGHT | Gravity.TOP,
-xy[0] / 2, xy[1] + button.getWidth());
// popupWindow.showAsDropDown(button,0, 0);
}
});
} // 创建一个包括自己定义view的PopupWindow
private PopupWindow makePopupWindow(Context cx) {
PopupWindow window;
window = new PopupWindow(cx); // View contentView =
// LayoutInflater.from(this).inflate(R.layout.popwindow, null);
// window.setContentView(contentView);
Button b1 = new Button(this);
b1.setText("first");
b1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT)); Button b2 = new Button(this);
b2.setText("Second");
b2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT)); LinearLayout linearLayout = new LinearLayout(this);
linearLayout.addView(b1);
linearLayout.addView(b2);
linearLayout.setOrientation(LinearLayout.VERTICAL); window.setContentView(linearLayout);
window.setBackgroundDrawable(getResources().getDrawable(
R.drawable.ic_launcher));
// window.setWidth(DisplayManager.dipToPixel(150));
// window.setHeight(DisplayManager.dipToPixel(150));
window.setWidth(150);
window.setHeight(150); // 设置PopupWindow外部区域是否可触摸
window.setFocusable(true); // 设置PopupWindow可获得焦点
window.setTouchable(true); // 设置PopupWindow可触摸
window.setOutsideTouchable(true); // 设置非PopupWindow区域可触摸
return window;
}
}</span>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:orientation="horizontal" > <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Title" /> <Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click" />
</LinearLayout> </LinearLayout></span>
王立平--PopupWindow的更多相关文章
- 王立平--TableLayout
效果: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android= ...
- 王立平--EditPlus激活码
注冊名:Free User 注冊码:6AC8D-784D8-DDZ95-B8W3A-45TFA
- 王立平-Android中对图像进行Base64编码
// ------------------base64-------------------// public String bitmaptoString(Bitmap bitmap) { // 将B ...
- 王立平--android事件监听的3种方式
第一种通常在activity组件的oncreate事件中直接定义,直接动作. 这样的方式每一个控件都定义一次.通常不方便. Button btn = (Button) findViewById(R.i ...
- 王立平-- ContentValues , HashTable , HashMap差别
ContentValues :是一种存储机制,key-value 特点:key仅仅能是string类型.value:仅仅能是基本类型,不能是对象. 应用:经常使用语往数据库中插入数据 Content ...
- 王立平--eclipse向svnserver上传项目
1.team-->share project watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQyNTUyNw==/font/5a6L5L2 ...
- 王立平--android中的anim(动画)
简单有用步骤: 1.新建anim目录. 2.在anim下新建xml文件, 3.在xml下编写自己须要动画. 简单样例: 给Imageview加入动画 public class MainActivity ...
- 王立平--Unity中间GUI Skin
C#文字: public class NewBehaviourScript2 : MonoBehaviour { public Texture t; public GUISkin skin; // U ...
- 王立平--Failed to push selection: Read-only file system
往android模拟器导入资源,失败. 提示:仅仅读文件. mnt是仅仅读文件.应点击sdcard.,在导入
随机推荐
- iOSAPP启动时实现加载广告
现在很多APP在启动的时候都在加载广告,现在也很流行,主要是盈利啊.笔者也做了很多关于广告的事情.现在记录下自己在APP启动的时候,怎么加载广告的. 下面总结下广告加载的三种方式 1.现在很多APP的 ...
- iOS弹出底部视图简单实现
- 项目基本目录 其中xib文件用来自定义需要弹出的视图. 在主控制器里设置popview的frame等信息代码如下: 底部视图(popview)初始化放在父类视图的最顶部或者说是整个屏幕的最底部,宽 ...
- ARM流水线(pipeline)
- 随手记今天跟的几个iOS项目代码的问题
休了一阵子假期,今天刚回来上班,项目代码已经有挺大的变化了,我就先体验.发现.跟进问题. 第一个问题是点击某个cell就挂掉的现象,同事表示必现但挺神奇.由于挂掉的时候没有啥有意义的信息,所以先简单粗 ...
- nginx+apache 404错误页面
公司新系统 随风做的 给客户演示出错不想让客户看到 自动返回上一页面. 刚开始按照网上说的 在nginx 处理: # 定义错误提示页面 error_page 500 502 503 504 / ...
- Struts1的处理流程
本文从收到一个请求开始讲述,忽略之前的filter等工作. 处理工作的主要承担者为RequestProcessor 1.处理请求的url. RequestProcessor.processPath(r ...
- java -- 轻量级锁
在了解轻量级锁之前,首先要知道什么是CAS CAS--Compare And Swap 比较并交换--通过比较传入的旧值和原内存位置中的值比较,来决定是不是要更新数据. CAS的语义是“我认为V的值应 ...
- Chapter 4.开放-封闭原则
开放-封闭原则:是说软件实体应该可以扩展,但不可修改. 设计人员必须对于他设计的模块应该对哪种变化封闭做出选择,先猜测出最有可能发生的变化种类,然后构造抽象来隔离那些变化. 面对需求,对程序的改动是通 ...
- Python 数据处理扩展包: pandas 模块的DataFrame介绍(读写数据库的操作)
1.读取表中的内容,如下例子: import MySQLdb try: conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='root ...
- CString 操作指南
过阅读本文你可以学习如何有效地使用 CString. CString 是一种很有用的数据类型.它们很大程度上简化了MFC中的许多操作,使得MFC在做字符串操作的时候方便了很多.不管怎样,使用CStri ...