获取popupwindow宽度 怎么获取window

Popupwindow中的按钮监听咋弄啊?
[问题点数:20分,结帖人hu_344]
Popupwindow中的按钮监听咋弄啊?
[问题点数:20分,结帖人hu_344]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2014年6月 移动开发大版内专家分月排行榜第二
2014年8月 移动开发大版内专家分月排行榜第三
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。popupWindow获取焦点后,parent如何响应点击事件
[问题点数:40分,结帖人q5620258]
popupWindow获取焦点后,parent如何响应点击事件
[问题点数:40分,结帖人q5620258]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2012年2月 移动平台大版内专家分月排行榜第二2012年1月 移动平台大版内专家分月排行榜第二2011年5月 移动平台大版内专家分月排行榜第二2011年4月 移动平台大版内专家分月排行榜第二2009年1月 移动平台大版内专家分月排行榜第二
2011年12月 移动平台大版内专家分月排行榜第三2011年11月 移动平台大版内专家分月排行榜第三2011年9月 移动平台大版内专家分月排行榜第三2011年8月 移动平台大版内专家分月排行榜第三2010年3月 移动平台大版内专家分月排行榜第三2010年2月 移动平台大版内专家分月排行榜第三2009年4月 移动平台大版内专家分月排行榜第三2009年3月 硬件/嵌入开发大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。查看: 9850|回复: 19
怎样获得popupwindow高度
该用户从未签到主题帖子e币
没有eoe的账号,级别还太低,出门如何吹牛逼?
才可以下载或查看,没有帐号?
设置了popupwindow的高度为wrapcontent,怎样获得他的真实高度
popupwindow = new PopupWindow(createLayout,width, ViewGroup.LayoutParams.WRAP_CONTENT);
&&int width = popupwindow .getWidth();//得出的结果正确
&&int height = popupwindow .getHeight();//得出结果为-2
该用户从未签到主题帖子e币
该方法可行
popupWindow.getContentView().measure(0,0);
int height = popopWindow.getContentView().getMeasuredHeight();
这个确实可以。太感谢了&
这个方法可行 终于解决了&
签到天数: 92 天连续签到: 1 天[LV.6]常住居民II主题帖子e币
本帖最后由 rebooter 于
23:29 编辑
这个方法可行 终于解决了
用如下方法创建弹出框(window.xml 是popupWindow 布局文件)
LayoutInflater inflater = LayoutInflater.from(this);
& && && && && && && && &View view = inflater.inflate(R.layout.window, null);
& && && && && && && && &final PopupWindow popwin = new PopupWindow(view,
& && && && && && && && && && && && && & LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);复制代码然后
popwin.getContentView().measure(0,0);
int width = popwin.getContentView().getMeasuredWidth();复制代码想获取弹出框宽度,却出现空指针异常,看日志是定位到了popwin.getContentView().measure(0,0); 复制代码这个方法导致了nullpointException,但是打印popwin.getContentView() 并不是null,是什么导致了空指针异常呢?
同样的问题啊
不知道为什么
两台电脑一个正常一个报错&
该用户从未签到主题帖子e币
floatPopu.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
& & & & @Override
& & & & public void onGlobalLayout() {
& & & & & & & & // TODO Auto-generated method stub
& & & & & & & & int[] location = new int[2];
& & & & & & & & v.getLocationOnScreen(location);
& & & & & & & & LogUtil.i(TAG, &---floatPopu---& + floatPopu.getHeight());
& & & & & & & & LogUtil.i(TAG, &---x---&+location[0]+&------Y---&+ location[1]);
& & & & & & & & LogUtil.i(TAG, &---popuwindHeight---& + popupWindow.getHeight());
& & & & & & & &
& & & & & & & & popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, location[0],
& & & & & & & & & & & & & & & & location[1] - floatPopu.getHeight());
该用户从未签到主题帖子e币
在正确的时候获取.
因为View没有去绘制之前去获取,是获取不到的,一样的道理
该用户从未签到主题帖子e币
我必须在他显示出来之前知道他的高度,。怎么办
该用户从未签到主题帖子e币
你这个问题等于是&我不想知道这个东西的高度,我想在它显示出来之前又想知道它的高度&,这个挺矛盾啊.你自己到底想要什么,得想清楚.
该用户从未签到主题帖子e币
我急需要各个demo
签到天数: 2 天连续签到: 1 天[LV.1]初来乍到主题帖子e币
popupwindow = new PopupWindow(createLayout,width, ViewGroup.LayoutParams.WRAP_CONTENT);
popupwindow.post(new Runnable(){
&&int width = popupwindow .getWidth();//得出的结果正确
&&int height = popupwindow .getHeight();//得出结果为-2
这种写法有问题吧&
该用户从未签到主题帖子e币
kris 发表于
popupwindow = new PopupWindow(createLayout,width, ViewGroup.LayoutParams.WRAP_CONTENT);
popupwindow. ...
这种写法有问题吧
该用户从未签到主题帖子e币
一样的问题
该用户从未签到主题帖子e币
我也遇到了同样的问题,正在寻找答案
签到天数: 82 天连续签到: 1 天[LV.6]常住居民II主题帖子e币
同样的问题我也遇到了。。。蛋疼呀
签到天数: 82 天连续签到: 1 天[LV.6]常住居民II主题帖子e币
楼主这问题解决了吗??
该用户从未签到主题帖子e币
该方法可行
popupWindow.getContentView().measure(0,0);
int height = popopWindow.getContentView().getM ...
这个方法可行 终于解决了
用如下方法创建弹出框(window.xml 是popupWindow 布局文件)
想获取弹出框宽度,却出现空指针异常,看日志是定位到了这个方法,但是打印popwin.getContentView() [/backcolor]并不是null,是什么导致了空指针异&
该用户从未签到主题帖子e币
我用这个方法popupWindow.getContentView().measure(0,0);
int height = popopWindow.getContentView().getMeasuredHeight(); 开始 还可以获取成功 后面 就这么获取不能成功了
QQ已认证,此人靠谱
社区贡献者
eoeAndriod社区贡献网友
社区认证会员
社区认证会员
推荐阅读热门话题
620001881417415378325277276259256251225217210715
半小时前7&小时前7&小时前7&小时前昨天&23:56昨天&19:40昨天&18:01昨天&14:18昨天&12:29昨天&11:25昨天&10:08昨天&10:06前天&23:54前天&10:54前天&10:523&天前
Powered by15:11 提问
如何从 PopUpWindow 中获取 editText input?
在一个popupwindow中如何从一个editText box中获取input。我用了2种方法,一种是使用layout inflator。
另一种方法没有使用layout inflator,尽管我在box中输入信息,但是获得""或者null。
返回""的方法:
View inflatedView = getLayoutInflater().inflate(R.layout.login_popup, null);
EditText usernameInput = (EditText) inflatedView.findViewById(R.id.username_login_input);
EditText passwordInput = (EditText) inflatedView.findViewById(R.id.password_login_input);
final String usernameString = usernameInput.getText().toString();
final String passwordString = passwordInput.getText().toString();
返回 null 的方法:
EditText usernameInput = (EditText) findViewById(R.id.username_login_input);
EditText passwordInput = (EditText) findViewById(R.id.password_login_input);
final String usernameString = usernameInput.getText().toString();
final String passwordString = passwordInput.getText().toString();
我想从 login_popup.xml 中获取,这不是从一个 activity 中生成的。
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.login_popup, null);
ppw = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
ViewGroup parentLayout = (ViewGroup) findViewById(R.id.title_page_layout);
// set the position and size of popup
ppw.showAtLocation(parentLayout, Gravity.CENTER, 10, 20);
按赞数排序
第一种方法是正确的,第二种是错误的
19038关注|1641收录
其他相似问题Android PopupWindow显示位置和显示大小 - 推酷
Android PopupWindow显示位置和显示大小
&?xml version=&1.0& encoding=&utf-8&?&
&LinearLayout xmlns:android=&/apk/res/android&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:background=&#DA4F30&
android:cacheColorHint=&#000000&
android:orientation=&vertical& &
android:id=&@+id/lv_dialog&
android:layout_width=&match_parent&
android:layout_height=&match_parent&
android:cacheColorHint=&#&
android:scrollbars=&none&
android:overScrollMode=&never&&
&/ListView&
&/LinearLayout&
package com.example.
import android.app.A
import android.content.C
import android.graphics.drawable.BitmapD
import android.os.B
import android.view.G
import android.view.LayoutI
import android.view.V
import android.view.View.OnClickL
import android.view.W
import android.view.WindowM
import android.widget.AdapterV
import android.widget.AdapterView.OnItemClickL
import android.widget.ArrayA
import android.widget.ImageV
import android.widget.LinearL
import android.widget.ListV
import android.widget.PopupW
public class MainActivity extends Activity {
private LinearL
private ListView listV
private PopupWindow popupW
private String title[] = { &1&, &2&, &3&, &4&, &5& };
ImageView imageV
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
imageView=(ImageView) findViewById(R.id.imageview_above_more);
imageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showPopupWindow(imageView);
public void showPopupWindow(View parent) {
//加载布局
layout = (LinearLayout) LayoutInflater.from(MainActivity.this).inflate(
R.layout.dialog, null);
//找到布局的控件
listView = (ListView) layout.findViewById(R.id.lv_dialog);
//设置适配器
listView.setAdapter(new ArrayAdapter&String&(MainActivity.this,
R.layout.text, R.id.tv_text, title));
// 实例化popupWindow
popupWindow = new PopupWindow(layout, 300,500);
//控制键盘是否可以获得焦点
popupWindow.setFocusable(true);
//设置popupWindow弹出窗体的背景
popupWindow.setBackgroundDrawable(new BitmapDrawable(null,&&));
WindowManager manager=(WindowManager) getSystemService(Context.WINDOW_SERVICE);
@SuppressWarnings(&deprecation&)
//获取xoff
int xpos=manager.getDefaultDisplay().getWidth()/2-popupWindow.getWidth()/2;
//xoff,yoff基于anchor的左下角进行偏移。
popupWindow.showAsDropDown(parent,xpos, 0);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView&?& arg0, View arg1, int arg2,
long arg3) {
//关闭popupWindow
popupWindow.dismiss();
popupWindow =
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 popupwindow背景变暗 的文章

 

随机推荐