【问题标题】:PopupWindow Width and Height弹出窗口宽度和高度
【发布时间】:2011-10-20 06:21:15
【问题描述】:

好的,所以我开始掌握构建 Android 应用程序的窍门,至少几天后程序员可以做到 - 我为我迄今为止所学到的东西感到自豪。

无论如何,我想强制登录主要活动 - 我这样做是通过获取 SharedPrefernece 并检查该信息是否为空,而不是获取包含“登录”字段和选项的 PopupWindow。

This PopupWindow has a Flipper inside, which is fine and I got working fine when the certain options are choosen.

当我设置 PopupWindow.setAtLocation() 时,我无法将此 PopupWindow 显示为内容的大小 (wrap_content)

现在,这是我一直在尝试获取弹出窗口大小的方法 - 正如这里多次提到的:

popup.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
final PopupWindow pw = new PopupWindow(popup,popup.getMeasuredHeight(),popup.getMeasuredWidth(), true);

注意popup是Popup实际布局的inflator,pw是实际的PopupWindow对象。

现在,我想获取弹出窗口的实际大小(这样它就不会在页面上伸展,而是在看起来像正常弹出窗口应该的中心。

另外,使用 ViewFlipper。我希望它在切换页面时更新弹出窗口的大小(因此页面应该每页上下调整大小)有没有办法让它也能工作?我试过 pw.update() 但效果不是很好。

【问题讨论】:

    标签: android height width popupwindow


    【解决方案1】:

    您想要测量将添加到PopupWindow 的实际布局。我刚刚解决了将ListView 放入PopupWindow 的类似问题。诀窍是在您的View 中覆盖onMeasure()。每次更改时重新测量 ViewFlipper

    @Override
    public void onMeasure(int x, int y)
    {
        super.onMeasure(x, y);
    
        if(x == View.MeasureSpec.UNSPECIFIED && y == View.MeasureSpec.UNSPECIFIED)
        {
            //measure your child views here
    
            //tell the view it has been measured
            this.setMeasuredDimension(width, height);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      相关资源
      最近更新 更多