popupWindow的使用
来源:互联网 发布:truncate mysql 编辑:程序博客网 时间:2024/06/12 00:17
public class PopupWindowActivity extends Activity {
private Button mPopWinBtn;
private PopupWindow mPopWin;
private boolean hasMeasured;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPopWin = new PopupWindow(setPopWindowData());
mPopWinBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//加上是否显示,若已显示则清除掉存在的,不存在则显示
if (mPopWin.isShowing()) {
mPopWin.dismiss();
} else {
mPopWin.showAsDropDown(v);
}
}
});
/*
* 让下拉框显示出来,无这部分则不会显示
*/
ViewTreeObserver vto = mPopWinBtn.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
if (hasMeasured == false) {
int btWidth = mPopWinBtn.getMeasuredWidth(); // 得到按钮宽度
int btHeight = mPopWinBtn.getMeasuredHeight(); // 得到按钮高度
mPopWin.setWidth(btWidth); // 设置宽高属性,两属性缺一不可
mPopWin.setHeight(500);
hasMeasured = true;
}
return true;
}
});
}
public View setPopWindowData() {
// 此处直接使用适配器控件布局,若加入外部布局则会报错
View v = LayoutInflater.from(this).inflate(
R.layout.pop_window_listview, null);
ListView content = (ListView) v;
String[] popData = { "添加", "删除", "修改", "插入" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, popData);
content.setAdapter(adapter);
return content;
}
private Button mPopWinBtn;
private PopupWindow mPopWin;
private boolean hasMeasured;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popwindow_view);
mPopWinBtn = (Button) findViewById(R.id.pop_window_btn);mPopWin = new PopupWindow(setPopWindowData());
mPopWinBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//加上是否显示,若已显示则清除掉存在的,不存在则显示
if (mPopWin.isShowing()) {
mPopWin.dismiss();
} else {
mPopWin.showAsDropDown(v);
}
}
});
/*
* 让下拉框显示出来,无这部分则不会显示
*/
ViewTreeObserver vto = mPopWinBtn.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
if (hasMeasured == false) {
int btWidth = mPopWinBtn.getMeasuredWidth(); // 得到按钮宽度
int btHeight = mPopWinBtn.getMeasuredHeight(); // 得到按钮高度
mPopWin.setWidth(btWidth); // 设置宽高属性,两属性缺一不可
mPopWin.setHeight(500);
hasMeasured = true;
}
return true;
}
});
}
public View setPopWindowData() {
// 此处直接使用适配器控件布局,若加入外部布局则会报错
View v = LayoutInflater.from(this).inflate(
R.layout.pop_window_listview, null);
ListView content = (ListView) v;
String[] popData = { "添加", "删除", "修改", "插入" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, popData);
content.setAdapter(adapter);
return content;
}
}
xml 文件
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pop_window_list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
0 0
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用!!!
- 关于popupWindow的使用
- PopupWindow的使用
- PopupWindow的使用例子
- PopupWindow的使用
- popupWindow的使用心得
- PopupWindow的使用
- PopupWindow的使用
- Android PopupWindow的使用!!!
- PopupWindow的使用
- PopupWindow的使用
- popupWindow的使用
- PopupWindow的使用
- PopupWindow的使用
- Popupwindow的使用
- PopupWindow的使用
- WebView注入Javascript的版本兼容问题
- java万年历
- yeoman、bower、grunt 开发收集
- struts异常:HTTP Status 404 - There is no Action mapped for namespace [/] and action name [promotion]
- Codevs 玛丽卡
- popupWindow的使用
- [TwistedFate]程序存储区划分、动态申请内存、内存操作函数
- IOS开发笔记3-SCANF函数使用和表达式
- 《我眼中的机器学习》 --1 【数学基石】
- 如何监控Java垃圾回收机制2
- OC学习笔记之NSString常见处理方法
- iO8及以后设置启动图片LaunchImage的方法
- 杭电2473-Junk-Mail Filter
- 15年亚洲区长春站赛后总结