今天了解到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. Tinyhttpd精读解析

    首先,本人刚刚开始开源代码精读,写的不对的地方,大家轻拍,一起进步.本文是对Tinyhttpd的一次精读,大家每天都在用着http服务,很多人也一直活跃在上层,使用IIS.Apache等,大家是否想看 ...

  2. Mybatis主配置文件常见使用讲解

    在开发中我们通常将Mybatis中配置文件分两种,主配置文件与和dao对应的映射文件. 其实最后mybatis解析的还是一个主配置文件. 而映射文件会通过我们配置<mappers>属性,或 ...

  3. 翻译连载 | 第 11 章:融会贯通 -《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇

    原文地址:Functional-Light-JS 原文作者:Kyle Simpson-<You-Dont-Know-JS>作者 关于译者:这是一个流淌着沪江血液的纯粹工程:认真,是 HTM ...

  4. C#.Net调用VB.Net中的MY

    用过VB.NET的人应该只要MY有多强大了吧,是不是很想在C#中也能调用呢? 当然是可以的,.net作为微软的跨语言的平台,必须是能实现的,不然微软就自己打自己嘴巴了~ 回到正题上: 1.在程序中加上 ...

  5. 最近ssh遇到异常及解决

    1.SSH框架,spring和struts整合,action中注入service不成功,检测是否缺少 struts2-spring-plugin-2.3.4.1.jar包 2.字符串转 json 加了 ...

  6. python基础阶段练习题 拾英札记(1)

    python很灵活,学起来有人机交互的快乐感,贵在坚持. 做题对自学python很有帮助,融汇贯通-查漏补缺-巩固提高. 写了一些注释,希望能对您有所帮助. #1.输入一个3位数,计算个位.百位.十位 ...

  7. SDRAM操作说明

    SDRAM是做嵌入式系统中,常用是的缓存数据的器件.基本概念如下(注意区分几个主要常见存储器之间的差异): SDRAM(Synchronous Dynamic Random Access Memory ...

  8. 《 iPhone X ARKit Face Tracking 》

    欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 本文来自于腾讯Bugly公众号(weixinBugly), 作者:jennysluo,未经作者同意,请勿转载,原文地址:http://mp.w ...

  9. Openning

    In order to imporve my english writing skill and enhance my understanding of  programming ,I'm setti ...

  10. Microsoft SQL Server 2008 R2数据库备份 - 人工备份

    业务介绍 数据库人工备份是指由相关管理人员通过主动的手工方式备份数据库文件.在一些特殊的时间节点,如重要资料的录入完成.软硬件环境更新前等需要特别关注数据库安全的时候,一定要进行数据库的人工备份,以保 ...