今天了解到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. Android 开发笔记___实战项目:购物车

    购物车的应用很广泛,电商app基本上都有它的身影.由于它用到了多种存储方式,通过项目对数据的存储有更高层次的了解. 1.设计思路 首先看看购物车的外观.第一次进入时里面是空的,去购物页面加入购物车以后 ...

  2. Java面试题解构

    有次一个同事让我一同去面试一个候选人,没仔细看简历,所以在问了设计模式之后就让他谈一谈对内存泄漏和垃圾回收的理解,当时候选人一下子就懵了.后来才知道,他面的是初.中级开发职位,想来估计候选人心里也在骂 ...

  3. Task及Mvc的异步控制器 使用探索

    微软的Task已经出来很久了,一直没有去研究,以为就是和Thread差不多的东西.直到最近看到了Task的使用介绍,发现比Thread的语法要精炼多了,于是便在项目中用上了. 结果就出问题了,数据库连 ...

  4. 05).30分钟学会Servlet+过滤器+监听器+实际案例

    一.Servlet简介: Servlet程序处理流程 二.Servlet程序实现 实现要求 Servlet属于java ee范畴,而java和javac属于java se范畴,要想编译servlet必 ...

  5. HTTP请求过程(http是一种无状态协议,即不建立持久的连接)

    一.一个完整的HTTP请求,通常有7个步骤: 1.建立TCP连接: 2.web浏览器向web服务器发送请求命令: 3.浏览器发送请求头信息: 4.服务器应答: 5.服务器发送应答头信息: 6.服务器向 ...

  6. C# 4.0 新特性dynamic、可选参数、命名参数等

    1.dynamic ExpandoObject熟悉js的朋友都知道js可以这么写 :   1 var t = new Object(); 2 t.Abc = ‘something’; 3 t.Valu ...

  7. C#中消息的工作流程

    C#中的消息被Application类从应用程序消息队列中取出,然后分发到消息对应的窗体,窗体对象的第一个响应函数是对象中的protected override void WndProc(ref Sy ...

  8. Hive 学习笔记(启动方式,内置服务)

    一.Hive介绍 Hive是基于Hadoop的一个数据仓库,Hive能够将SQL语句转化为MapReduce任务进行运行. Hive架构图分为以下四部分. 1.用户接口 Hive有三个用户接口: 命令 ...

  9. [转载] TCP长连接与短连接的区别

    转载自http://www.cnblogs.com/liuyong/archive/2011/07/01/2095487.html 1. TCP连接 当网络通信时采用TCP协议时,在真正的读写操作之前 ...

  10. ByteArrayInputStream&ByteArrayOutputStream源码分析

    #ByteArrayInputStream 源码 ``` public synchronized int read(byte b[], int off, int len) { if (b == nul ...