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>
技术分享

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。