zoukankan      html  css  js  c++  java
  • Android PopupWindow底部菜单

     

    底部菜单实例

    import java.util.Timer; 
    import java.util.TimerTask; 
      
    import android.app.Activity; 
    import android.content.Context; 
    import android.os.Bundle; 
    import android.os.Handler; 
    import android.os.Message; 
    import android.view.Gravity; 
    import android.view.LayoutInflater; 
    import android.view.View; 
    import android.view.ViewGroup.LayoutParams; 
    import android.widget.PopupWindow; 
      
    public class MainActivity extends Activity { 
        private Handler handler = new Handler() { 
            public void handleMessage(Message msg) { 
                switch (msg.arg1) { 
                case 1: 
                    showBottomMenu(); 
                    break; 
                } 
            } 
        }; 
      
        @Override
        public void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main); 
      
            Timer timer = new Timer(); 
            timer.schedule(new initBottomMenu(), 100); 
        } 
      
        private class initBottomMenu extends TimerTask { 
            @Override
            public void run() { 
                Message msg = new Message(); 
                msg.arg1 = 1; 
                handler.sendMessage(msg); 
            } 
        } 
      
        /** 
         * 显示底部菜单 
         */
        public void showBottomMenu() { 
            LayoutInflater mLayoutInfalter = (LayoutInflater) this
                    .getSystemService(LAYOUT_INFLATER_SERVICE); 
            View menuView = mLayoutInfalter.inflate(R.layout.menu, null); 
            PopupWindow mPopupWindow = new PopupWindow(menuView, 
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
      
            mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM, 0, 
                    0); 
        } 
    }

    主界面的布局文件:main.xml

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main" 
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"> 
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="底部菜单实例" 
            /> 
    </LinearLayout>

    底部菜单的布局文件:menu.xml

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="horizontal" 
        android:background="@drawable/menu_back"> 
        <Button 
            android:id="@+id/menu_ensureButton"
            android:layout_width="160px" 
            android:layout_height="wrap_content"
            android:layout_marginTop="5px" 
            android:text="完成" 
            /> 
        <Button 
            android:id="@+id/menu_cancelButton"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_marginTop="5px" 
            android:text="取消" 
            /> 
    </LinearLayout>
  • 相关阅读:
    计算panel的靶向区段长度
    interval的排序,合并,取样等功能
    Bait 和 target的区别
    R 数据拆分到列
    制作annovar注释依赖的cosmic数据库
    制作适用于annovar的COSMIC数据库
    痘痘机理
    属性、域、元组、关系、候选码、主键、外键、关系代数
    how to install emacs25 in ubuntu 14
    Centos Install Emacs
  • 原文地址:https://www.cnblogs.com/xuewater/p/2810315.html
Copyright © 2011-2022 走看看