【发布时间】:2016-07-14 09:54:55
【问题描述】:
目前,我在Linear Layout 中有一个按钮,如下所示:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/open_popup"
android:onClick="createPopup"/>
</LinearLayout>
我还有一个 createPopup 扩展(在单击按钮时确实会执行)。
public void createPopup(View view) {
}
我尝试创建一个PopupWindow,其中包含TextView。然后我调用了showAtLocation(parent, gravity, x, y),其中parent 是根LinearLayout。 gravity 是 Gravity.BOTTOM,x 和 y 都设置为 10。
当我点击按钮时,我收到了一个IllegalStateException 错误,我调用了showAtLocation()。这是createPopup() 函数:
PopupWindow popUp;
LinearLayout layout;
LinearLayout main;
TextView value;
LayoutParams params;
boolean click = true;
public void createPopup(View view) {
popUp = new PopupWindow(this);
layout = new LinearLayout(this);
main = (LinearLayout) findViewById(R.id.parent);
value = new TextView(this);
if(click) {
popUp.showAtLocation(main, Gravity.BOTTOM, 10, 10);
popUp.update(50, 50, 300, 80);
click = false;
} else {
popUp.dismiss();
click = true;
}
params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
value.setText(R.string.message);
layout.addView(value, params);
popUp.setContentView(layout);
setContentView(main);
TextView status = (TextView) findViewById(R.id.status);
status.setTextSize(28);
status.setText("Status of Popup: Don't worry, you're never going to get this.");
}
我想知道的是:
- 这个错误是什么意思?
- 为什么会出现?
- 我该如何解决?
- 如何创建一个在单击按钮时出现的简单弹出窗口?*
*我希望能够创建一个函数,它至少需要一个参数(这将是一个String),然后创建一个包含该String 的弹出窗口,以及一个按钮关闭弹出窗口。
编辑:不确定这是否与弹出问题有关,但是当我运行应用程序时,出现此错误:
07-13 19:51:48.448 133-133/? E/[EGL-ERROR]: egl_image* _egl_create_image_ANDROID_native_buffer(egl_display*, egl_context*, EGLClientBuffer, EGLint*, void*):593: CHUN try create image with crop 0,0,0,0
[ 07-13 19:51:48.448 133: 133 E/ ]
CHUN map external image rgb 1024 x 600
第二次编辑:我在上面添加了相关代码。
【问题讨论】:
-
发布错误的完整堆栈跟踪。包括错误消息,这很重要。
-
不知道能不能重现,但我可以试试。
-
请确保在给出错误时使用五个完整的堆栈跟踪,这对于理解正在发生的事情非常有帮助。
-
对不起,我不知道。下次我会这样做。
标签: java android android-linearlayout illegalstateexception android-popupwindow