android popwindow 使用 转http://www.cnblogs.com/jenson138/p/4335818.html

android PopupWindow使用实例

 

.java

复制代码
 1 private PopupWindow mMenu;
 2 
 3 
 4     public void CreatMenu(View view) {
 5         if (mMenu == null) {
 6             LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 7             View v = inflater.inflate(R.layout.popuppindow_group,
 8                     null, false);
 9             LinearLayout lytRequest = (LinearLayout) v.findViewById(R.id.lyt_pw_groupmember_request);
10             lytRequest.setOnClickListener(this);
11             LinearLayout lytExit = (LinearLayout) v.findViewById(R.id.lyt_pw_groupmember_exit);
12             lytExit.setOnClickListener(this);
13             mMenu = new PopupWindow(v);
14 //            moreMenu.setWidth(300);
15             mMenu.setWidth(LayoutParams.WRAP_CONTENT);
16             mMenu.setHeight(LayoutParams.WRAP_CONTENT);
17             mMenu.showAsDropDown(view);
18         } else {
19             if (mMenu.isShowing()) {
20                 mMenu.dismiss();
21             } else {
22                 mMenu.showAsDropDown(view);
23             }
24         }
25     }    
26 
27 @Override
28     public void onClick(View v) {
29         // TODO Auto-generated method stub
30         switch (v.getId()) {
31          case R.id.lyt_activitygroupmembers_menu:
32              CreatMenu(v);
33          break;
34          case R.id.lyt_pw_groupmember_request:
35              Toast.makeText(this, "request", Toast.LENGTH_SHORT).show();
36              mMenu.dismiss();
37          break;
38          case R.id.lyt_pw_groupmember_exit:
39              Toast.makeText(this, "exit", Toast.LENGTH_SHORT).show();
40              mMenu.dismiss();
41          break;         
42          
43         }
44 
45     }
复制代码

 

.xml

复制代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/darker_gray" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/lyt_pw_groupmember_request"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/TextView03"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:gravity="left|center"
                android:text="request"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/TextView04"
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:background="@android:color/darker_gray"
                android:text="TextView" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/lyt_pw_groupmember_exit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/TextView02"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:gravity="left|center"
                android:text="exit"
                android:textSize="18sp" />

        </LinearLayout>

    </LinearLayout>
    

</RelativeLayout>
复制代码
posted @ 2015-03-13 23:29  -琥珀川-  阅读(186)  评论(0编辑  收藏  举报