对技术执着
分类: LINUX
2015-07-08 17:51:14
复制代码
- // WindowManager.LayoutParams lp = getWindow().getAttributes();
- // lp.alpha = 0.5f; //0.0-1.0
- // getWindow().setAttributes(lp);
弹出popwindow的代码如下,比较乱,多包涵:
复制代码
- popupWindow = new PopupWindow(menuView, LayoutParams.FILL_PARENT,
- LayoutParams.FILL_PARENT, true);
- popupWindow.showAtLocation(findViewById(R.id.parent), Gravity.CENTER
- | Gravity.CENTER, 0, 0);
- popupWindow.setAnimationStyle(R.style.PopupAnimation);
- // 加上下面两行可以用back键关闭popupwindow,否则必须调用dismiss();
- ColorDrawable dw = new ColorDrawable(-00000);
- popupWindow.setBackgroundDrawable(dw);
- popupWindow.update();
复制代码
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android=" />
- android:orientation="vertical" android:layout_width="fill_parent"
- android:gravity="center" android:layout_height="fill_parent"
- android:layout_gravity="center" android:background="#b0000000" >
- <LinearLayout android:orientation="vertical"
- android:layout_width="wrap_content" android:gravity="center"
- android:layout_height="wrap_content" android:layout_gravity="center"
- android:background="@drawable/downbutton_corner">
- <GridView android:id="@+id/gridview" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:numColumns="4"
- android:verticalSpacing="5dip" android:horizontalSpacing="5dip"
- android:stretchMode="columnWidth" android:gravity="center"
- android:layout_gravity="center" /></LinearLayout></LinearLayout>
复制代码
- <shape xmlns:android=" />
- android:shape="rectangle">
- <gradient android:startColor="#c0000000" android:endColor="#c0000000"
- android:angle="90" /><!--背景颜色渐变 -->
- <stroke android:dashWidth="2dp" android:dashGap="2dp"
- android:width="2dp" android:color="#FF00ff00"></stroke>
- <!--描边 -->
- <corners android:bottomRightRadius="5dp"
- android:bottomLeftRadius="5dp" android:topLeftRadius="5dp"
- android:topRightRadius="5dp" /><!--设置圆角-->
- </shape>
复制代码
- <set xmlns:android=" />
- <scale android:fromXScale="0.6" android:toXScale="1.0"
- android:fromYScale="0.6" android:toYScale="1.0" android:pivotX="50%"
- android:pivotY="50%" android:duration="5000" />
- <alpha android:interpolator="@android:anim/decelerate_interpolator"
- android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="5000" />
- </set>
问题解决了,是因为没设置背景的原因。
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//把这一行放在showAtLocation前面就行了,以前是放在后面的,粗心了。
popupWindow.showAtLocation(findViewById(R.id.parent), Gravity.CENTER
| Gravity.CENTER, 0, 0);
网上也有很多人说,弹出pop之后,不响应键盘事件了,这个其实是焦点在pop里面的view去了。
以这个为例,焦点就在gridview上面去了。28楼的兄弟提示的,谢了。
在gridview加上setOnKeyListener,就能解决。[ code]/**复制代码
- menuGrid.setOnKeyListener(new OnKeyListener() {
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_MENU:
- if (popupWindow != null && popupWindow.isShowing()) {
- popupWindow.dismiss();
- System.out.println("menuGridfdsfdsfdfd");
- }
- break;
- }
- return true;
- }
- });
* ColorDrawable dw = new ColorDrawable(-00000);
* popupWindow.setBackgroundDrawable(dw);
* 本来看了个示例,加上上面这两行就不用调用dismiss,点击窗口之外的部位,或者按back键都能关闭窗口。 但是我这样写了,还是不行。
* 而且竟然捕获不到键盘事件,杯具,希望哪个解决了这个问题告诉我,谢谢。 ytdcr@tom.com
*/
/*
* @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch
* (keyCode) { case KeyEvent.KEYCODE_BACK: if (popupWindow != null) {
* popupWindow.dismiss(); }
*
* Toast.makeText(this, "fd", 1000).show(); break;
*
* } return super.onKeyUp(keyCode, event); }
*/[/code]