首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PopupWindow未显示

PopupWindow未显示
EN

Stack Overflow用户
提问于 2014-10-02 16:21:18
回答 1查看 3.2K关注 0票数 1

我为这个问题找到了许多解决办法,但没有一个对我有用。我想在片段中显示一个PopupWindow。这是我的密码

代码语言:javascript
复制
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View popupView = layoutInflater.inflate(R.layout.pop_up_cargando, null,false);
this.popupWindow = new PopupWindow(popupView, popupView.getWidth(),popupView.getHeight());
this.popupWindow.setFocusable(true);
int location[] = new int[2];
this.btnInventario.getLocationOnScreen(location);
this.popupWindow.showAtLocation(this.btnInventario, Gravity.NO_GRAVITY, location[0], location[1] + btnInventario.getHeight()); // this.btnInventario is the button that calls this code
this.popupWindow.update(0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

但是PopupWindow从来没有出现过。

编辑:这是pop_up_cargando的内容

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_recomendar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:orientation="vertical" >
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="180dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"
        android:id="@+id/cargando"/>
    <TextView
        android:id="@+id/txtTexto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_gravity="center"
        android:text="@string/vacio"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

有什么建议吗?我做错什么了?非常感谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-02 17:18:05

您的popupView.getWidth()popupView.getHeight()值等于0,因为尚未绘制视图。

在询问视图的宽度和高度之前,您必须确保已经绘制了它。为此,您可以在以下方法充气后调用它:

代码语言:javascript
复制
popupView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);

在此之后,您的视图的大小可以使用getMeasuredWidth()getMeasuredHeight()方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26165111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档