王立平--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.,在导入
随机推荐
- css 基础(一)
一.css样式表的分类 首先介绍一下css中的样式表 a.外部样式表 将需要的样式放在单独的外部文件中,需要使用是直接调用,通常放在.css文件中.例如:/*以下部分是放在(my.css)自定义名 ...
- python文件I/O
file = open(filename,mode) ,python使用open或者file:打开文件,打开文件有几种模式,譬如酱紫: test = open(“txt.txt”,”w”),更多的参数 ...
- 【Eclipse】Failed to load the JNI shared library
这是因为JDK配置错误所导致的现象. 一般说来,新购笔记本会预装64位的windows系统,而在网上下载软件时,32位会优先出现在页面中(现在来说是这个情况,但我认为未来64位会越来越普及). 如果你 ...
- akka actor中的基本概念(学习小结)
注:本文章是看blog后的一个阶段小结,只作为个人笔记, 原文链接:http://www.iteblog.com/archives/1154 官网地址贴上:http://doc.akka.io/doc ...
- c++隐藏实例
隐藏:是指派生类的函数屏蔽了与其同名的基类函数,规则如下:(1)如果派生类的函数与基类的函数同名,但是参数不同.此时,不论有无virtual关键字,基类的函数将被隐藏(注意别与重载混淆). 很简单略去 ...
- Python实现 zip解压缩到指定目录
#!/bin/env python #-*- coding:utf-8 -*- import zipfile,os import platform,sys,os from zipfile import ...
- Week2(9月16日):动手做个简单的例子
Part I:提问 =========================== 1.什么是ASP.NET MVC? 2.MVC的英文? 3.什么是模型? 4.什么是控制器? 5.什么是视图? 6.ASP ...
- hdu 1251 统计难题 初识map
Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单词本身也是 ...
- SimpleAdapter
1.视图 1)主视图 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...
- 国产CPU走到十字路口:谁来取代英特尔芯片?(少写了一个OpenPower)
国内的几支CPU研发力量各自选择的指令体系都有自己的优点和问题,选择其中的哪一支都会有对应的成本和风险.最终谁能担大任,且拭目以待. 文 | 瞭望智库特约科技观察员 王强 用上内置国产CPU的个人电脑 ...