• 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>
    复制代码
  • 相关阅读:
    R的卸载和更新安装
    Holt-Winters原理和初始值的确定
    使用excel结合线性规划求解Holt-Winters参数
    Java_Number(装箱和拆箱)
    Java_运算符
    Java_Character类
    Java_String&StringBuilder&StringBuffer类
    Java_数组
    Java_修饰符
    Java_变量类型
  • 原文地址:https://www.cnblogs.com/Small-Life/p/4336237.html
Copyright © 2020-2023  润新知