PopupWindow|PopupWindow 点击按钮的泡泡

【PopupWindow|PopupWindow 点击按钮的泡泡】packagecom.example.popupwindow; importcom.example.popupwindow.R.drawable; importandroid.app.Activity; importandroid.graphics.drawable.BitmapDrawable; importandroid.os.Bundle; importandroid.view.Gravity; importandroid.view.Menu; importandroid.view.MenuItem; importandroid.view.View; importandroid.view.ViewGroup; importandroid.widget.BaseAdapter; importandroid.widget.GridView; importandroid.widget.ImageView; importandroid.widget.ListAdapter; importandroid.widget.PopupWindow; importandroid.widget.TextView; publicclassMainActivityextendsActivity{publicPopupWindow pw; @OverrideprotectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }publicvoiddian(View v){//点击事件View view = View.inflate(this, R.layout.popup_window,null); GridView viewById = (GridView) view.findViewById(R.id.gv); viewById.setAdapter(newMyActivity()); //设置九宫格//设置冒泡pw=newPopupWindow(view,ViewGroup.LayoutParams.MATCH_PARENT,//填充宽度ViewGroup.LayoutParams.WRAP_CONTENT); //包裹内容填充(内容是View的match填充父窗体,填充父窗体就是包裹内容,包裹内容-->View的填充父窗体--->(两个结合父类的wrap_..)--->GridView的包裹内容)pw.setBackgroundDrawable(newBitmapDrawable()); //可绘制的位图pw.setFocusable(true); //设置可聚焦的 //显示/消失//pw.showAsDropDown(v); //指定在控件上的按钮的下方出现//显示在屏幕下方(v是按钮v.getparent()是父布局,显示在什么位置,x水平的偏移量,y是垂直的偏移量)pw.showAtLocation((View) v.getParent(), Gravity.BOTTOM,0,0); }classMyActivityextendsBaseAdapter{int[] images={R.drawable.i1,R.drawable.i2,R.drawable.i3,R.drawable.i4,R.drawable.i5,R.drawable.i6,R.drawable.i7,R.drawable.i8,}; String []names={"1","2","3","4","5","6","7","8",}; @OverridepublicintgetCount(){// TODO Auto-generated method stubreturnnames.length; }@OverridepublicObjectgetItem(intposition){// TODO Auto-generated method stubreturnnames[position]; }@OverridepubliclonggetItemId(intposition){// TODO Auto-generated method stubreturnposition; }@OverridepublicViewgetView(intposition, View convertView, ViewGroup parent){// TODO Auto-generated method stubshuju shju=null; if(convertView==null){convertView=View.inflate(MainActivity.this, R.layout.item,null); shju=newshuju(); shju.iv_icon=(ImageView) convertView.findViewById(R.id.iv_icon); shju.text=(TextView) convertView.findViewById(R.id.text); convertView.setTag(shju); }else{shju=(shuju) convertView.getTag(); }shju.iv_icon.setImageResource(images[position]); shju.text.setText(names[position]); returnconvertView; }classshuju{ImageView iv_icon; TextView text; }}}

    推荐阅读