- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用弹出窗口在单击 edit-text 时显示一些 TextView 。但是弹出窗口没有显示在特定位置,它总是显示在左上角,这是我的代码,那里有什么问题
private void showPopup(Context context,final LinearLayout Parent) {
LayoutInflater layoutInflater = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = layoutInflater.inflate(R.layout.popup,MainActivity.parent,true);
// Creating the PopupWindow
final PopupWindow popupWindow = new PopupWindow(
layout,700,700);
popupWindow.setContentView(layout);
popupWindow.setHeight(500);
new Runnable(){
@Override
public void run() {
popupWindow.showAtLocation(layout, Gravity.CENTER,300,150);
}
};
}
最佳答案
尝试以下代码:
public static Rect locateView(View v)
{
int[] loc_int = new int[2];
if (v == null) return null;
try
{
v.getLocationOnScreen(loc_int);
} catch (NullPointerException e)
{
//Happens when the view doesn't exist on screen anymore.
return null;
}
Rect location = new Rect();
location.left = loc_int[0];
location.top = loc_int[1];
location.right = location.left + v.getWidth();
location.bottom = location.top + v.getHeight();
return location;
}
然后使用
popup.showAtLocation(parent, Gravity.TOP|Gravity.LEFT, location.left, location.bottom);
希望对你有帮助
关于android - 弹出 showAtLocation 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23992129/
谁能告诉我函数 PopupWindow.showAtLocation(View **parent**,int w,int h); 中参数“parent”的详细解释提前致谢! 最佳答案 Android
我正在使用弹出窗口在单击 edit-text 时显示一些 TextView 。但是弹出窗口没有显示在特定位置,它总是显示在左上角,这是我的代码,那里有什么问题 private void sho
我有一部 android 4.0 手机 A 和一部 4.4 平板电脑 B,它们都有一个软件导航栏。我用这个: showAtLocation(myView, Gravity.NO_GRAVITY, x,
我有一个从 View 扩展的类,我正在尝试使用这段代码显示一个 popupWindow public class dbView extends View implements View.OnTouch
不同的重力值如何影响 Android 中的 PopupWindow.showAtLocation()? 我在 PopupWindows showAtLocation 和 Gravity 上找不到好的文
这与这个问题有关: Android Nougat PopupWindow showAsDropDown(...) Gravity not working 但是,当我应用此修复程序时: if (andr
我想在屏幕中间显示我的弹出窗口。我在 MainActivity 的 OnCreate 中调用它。我无法理解如何获得 showAtLocation 所要求的父 View :public void sho
我使用以下代码在 android 中显示 PopupWindow,我想将弹出窗口固定到 Button, btnShowPopup = (Button)findViewById(R.id.btn
我一直在开发一个简单明了的文件管理器应用程序。我用于测试的设备是 LG Nexus 4 (v4.3) 和 Xperia x10i (v2.3.7)。 x10i 的性能虽然有点低迷,但没有问题。 轮换:
我正在尝试创建一个弹出窗口,启动时该弹出窗口将位于该屏幕的中心,并且其宽度不会占据整个屏幕,无论提示它的按钮位于何处。我还想增加透明度,以便用户能够模糊地看到现在在后台的 Activity ,但我也遇
我是一名优秀的程序员,十分优秀!