今天了解到PopupWindows这个布局,PopupWindow这个类用来实现一个弹出框,能够使用随意布局的View作为其内容,这个弹出框是悬浮在当前activity之上的。

以下是一个实例

xml文件

<LinearLayout

        android:id="@+id/ll_popup"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        android:background="#ffffff"

        android:orientation="vertical" >



        <TextView

            android:layout_width="match_parent"

            android:layout_height="1dp"

            android:background="#ff495a" />



        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="55dp"

            android:orientation="horizontal" >



            <Button

                android:id="@+id/item_popupwindows_camera"

                android:layout_width="match_parent"

                android:layout_height="55dp"

                android:background="@drawable/bt_nobgd"

                android:textColor="#585858"

                android:textSize="18sp"

                android:text="拍照" />

        </LinearLayout>



        <TextView

            android:layout_marginLeft="80dp"

            android:layout_width="match_parent"

            android:layout_height="1px"

            android:background="#f2f2f2" />



        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="55dp"

            android:orientation="horizontal" >



            <Button

                android:id="@+id/item_popupwindows_Photo"

                android:layout_width="match_parent"

                android:layout_height="55dp"

                android:background="@drawable/bt_nobgd"

                android:textColor="#585858"

                android:textSize="18sp"

                android:text="从相冊中选取" />

        </LinearLayout>



        <TextView

            android:layout_width="match_parent"

            android:layout_height="2dp"

            android:background="#f3f3f3" />



        <Button

            android:id="@+id/item_popupwindows_cancel"

            android:layout_width="match_parent"

            android:layout_height="55dp"

            android:background="@drawable/bt_nobgd"

            android:textColor="#585858"

            android:textSize="18sp"

            android:text="取消" />

    </LinearLayout>

MainActivity文件   用来实现拍照获取本地图库的功能。

package cn.pb.activity;





import java.io.File;



import com.example.pb_android.R;



import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.graphics.drawable.BitmapDrawable;

import android.net.Uri;

import android.os.Bundle;

import android.os.Environment;

import android.provider.MediaStore;

import android.view.Gravity;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup.LayoutParams;

import android.view.animation.AnimationUtils;

import android.view.Window;

import android.widget.Button;

import android.widget.LinearLayout;

import android.widget.PopupWindow;

import android.widget.TextView;



public class MainActivity extends Activity implements OnClickListener{



    private TextView t_send,t_ragion;

    private Button btn_images;

    

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);  

        setContentView(R.layout.activity_main);

        Init();

    }

    public void Init(){

        t_send = (TextView) findViewById(R.id.t_send);

        btn_images = (Button) findViewById(R.id.btn_images);

        t_ragion = (TextView) findViewById(R.id.t_ragion);

        

        t_send.setOnClickListener(this);

        btn_images.setOnClickListener(this);

        t_ragion.setOnClickListener(this);

    }

    @Override

    public void onClick(View v) {

        switch (v.getId()) {

        case R.id.t_send:

            break;

        case R.id.btn_images:

            new PopupWindows(MainActivity.this, v);

            break;

        case R.id.t_ragion:

            break;

        default:

            break;

        }

    }

    

    public class PopupWindows extends PopupWindow {



        public PopupWindows(Context mContext, View parent) {



            View view = View

                    .inflate(mContext, R.layout.item_popupwindows, null);

            view.startAnimation(AnimationUtils.loadAnimation(mContext,

                    R.anim.fade_ins));

            LinearLayout ll_popup = (LinearLayout) view

                    .findViewById(R.id.ll_popup);

            ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext,

                    R.anim.push_bottom_in_2));



            setWidth(LayoutParams.FILL_PARENT);

            setHeight(LayoutParams.FILL_PARENT);

            setBackgroundDrawable(new BitmapDrawable());

            setFocusable(true);

            setOutsideTouchable(true);

            setContentView(view);

            showAtLocation(parent, Gravity.BOTTOM, 0, 0);

            update();

            Button bt1 = (Button) view

                    .findViewById(R.id.item_popupwindows_camera);

            Button bt2 = (Button) view

                    .findViewById(R.id.item_popupwindows_Photo);

            Button bt3 = (Button) view

                    .findViewById(R.id.item_popupwindows_cancel);

            bt1.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {

                    Intent intent = new Intent(

                            MediaStore.ACTION_IMAGE_CAPTURE);

                    // 以下这句指定调用相机拍照后的照片存储的路径

                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri

                            .fromFile(new File(Environment

                                    .getExternalStorageDirectory(),

                                    "imageTemp.jpg")));

                    startActivityForResult(intent, 2);

                    dismiss();     //关闭Pop窗体

                }

            });

            bt2.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {

                    Intent intent = new Intent(Intent.ACTION_PICK, null);

                    intent.setDataAndType(

                            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,

                            "image/*");// 调用android的图库

                    startActivityForResult(intent, 1);

                    dismiss();

                }

            });

            bt3.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {

                    dismiss();

                }

            });

        }

    }



}

Android PopupWindows的更多相关文章

  1. Android PopupWindows使用

    源码测试示例: package com.example.popupwindown; import android.os.Bundle; import android.app.Activity; imp ...

  2. Android高手速成--第一部分 个性化控件(View)

    第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...

  3. 据说年薪30万的Android程序员必须知道的帖子

    Android中国开发精英 目前包括: Android开源项目第一篇--个性化控件(View)篇       包括ListView.ActionBar.Menu.ViewPager.Gallery.G ...

  4. Android开源项目分类汇总

    目前包括: Android开源项目第一篇——个性化控件(View)篇   包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...

  5. android 很多牛叉布局github地址(转)

    原文地址 http://blog.csdn.net/luo15309823081/article/details/41449929 点击可到达github-------https://github.c ...

  6. GitHub上史上最全的Android开源项目分类汇总 (转)

    GitHub上史上最全的Android开源项目分类汇总 标签: github android 开源 | 发表时间:2014-11-23 23:00 | 作者:u013149325 分享到: 出处:ht ...

  7. !! 据说年薪30万的Android程序员必须知道事

    http://www.th7.cn/Program/Android/201512/742423.shtml Android中国开发精英 目前包括: Android开源项目第一篇——个性化控件(View ...

  8. 【Android】Android开源项目分类汇总

    第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...

  9. GitHub 优秀的 Android 开源项目(转)

    今天查找资源时看到的一篇文章,总结了很多实用资源,十分感谢原作者分享. 转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介 ...

随机推荐

  1. ⒀bootstrap组件 选项卡 基础案例

      <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q ...

  2. HTML学习笔记 cs2D3D展示基础 第十四节 (原创) 参考使用表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 使用原生JavaScript的Canvas实现拖拽式图形绘制,支持画笔、线条、箭头、三角形、矩形、平行四边形、梯形以及多边形和圆形,不依赖任何库和插件,有演示demo

    前言 需要用到图形绘制,没有找到完整的图形绘制实现,所以自己实现了一个 - - 一.实现的功能 1.基于oop思想构建,支持坐标点.线条(由坐标点组成,包含方向).多边形(由多个坐标点组成).圆形(包 ...

  4. 高阶函数,柯里化,sort排序

    高阶函数概念 first class object:     函数在python中时一等公民.     函数也是对象,可调用的对象.     函数可以作为普通变量,参数,返回值等等. 高阶函数:    ...

  5. Vue Elementui 如何让输入框每次自动聚焦

    在项目优化中碰到一个小问题,在每次提示框显示的时候让提示框中的输入框聚焦.如下图.一般情况下提示框是隐藏的.点击了编辑才会弹出. 那么原生属性autofocus 只在模板加载完成时起作用,也就是说只有 ...

  6. mac电脑安装apache,不能启动

    因为mac系统是自带apach的 如果安装正确还是不能启动,有可能是 mac电脑自带apache功能,与安装的apache冲突. 这样关闭Mac自带apach即可. mac电脑apache命令:重启a ...

  7. Maven快速使用阿里云的代理maven仓库

    自从开源中国的maven仓库挂了之后就一直在用国外的仓库,慢得想要砸电脑的心都有了.如果你和我一样受够了国外maven仓库的龟速下载?快试试阿里云提供的maven仓库,从此不在浪费生命…… 仓库地址: ...

  8. linux操作系统基础篇(一)

    1.什么是linux? Linux是一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和UNIX的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的UNIX工具软件.应用程序 ...

  9. 移动端h5拍照压缩即时上传后台并预览

    项目经理让迭代一个功能,实时预览并上传到后台的功能,听到这立马想起了几个第三方插件去实现,mui  和api cloude万万没想到的是这个app前面使用ios 和安卓原生写的,然后mui和api c ...

  10. (二)部署solr7.1.0到tomcat

    solr7.1.0部署到tomcat8 官方表示solr5之后的版本不再提供对第三方容器的支持(不提供war包了). "旧式"solr.xml格式不再支持,核心必须使用core.p ...