Android PopupWindows
今天了解到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的更多相关文章
- Android PopupWindows使用
源码测试示例: package com.example.popupwindown; import android.os.Bundle; import android.app.Activity; imp ...
- Android高手速成--第一部分 个性化控件(View)
第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...
- 据说年薪30万的Android程序员必须知道的帖子
Android中国开发精英 目前包括: Android开源项目第一篇--个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.G ...
- Android开源项目分类汇总
目前包括: Android开源项目第一篇——个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...
- android 很多牛叉布局github地址(转)
原文地址 http://blog.csdn.net/luo15309823081/article/details/41449929 点击可到达github-------https://github.c ...
- GitHub上史上最全的Android开源项目分类汇总 (转)
GitHub上史上最全的Android开源项目分类汇总 标签: github android 开源 | 发表时间:2014-11-23 23:00 | 作者:u013149325 分享到: 出处:ht ...
- !! 据说年薪30万的Android程序员必须知道事
http://www.th7.cn/Program/Android/201512/742423.shtml Android中国开发精英 目前包括: Android开源项目第一篇——个性化控件(View ...
- 【Android】Android开源项目分类汇总
第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...
- GitHub 优秀的 Android 开源项目(转)
今天查找资源时看到的一篇文章,总结了很多实用资源,十分感谢原作者分享. 转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介 ...
随机推荐
- 初窥图像识别与k-means算法
前段时间做了一个车型识别的小项目,思路是利用k-means算法以及词袋模型来做的. 近年来图像识别的方法非常非常多,这边只记录一下我那个项目的思路,核心思想是k-means算法和词汇树. 很遗憾没有做 ...
- iOS隐藏导航栏底部灰线
首先创建 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #de38a5 } span.s1 { } span.s ...
- 【机器学习实战】第13章 利用 PCA 来简化数据
第13章 利用 PCA 来简化数据 降维技术 场景 我们正通过电视观看体育比赛,在电视的显示器上有一个球. 显示器大概包含了100万像素点,而球则可能是由较少的像素点组成,例如说一千个像素点. 人们实 ...
- Java_String_01_由转义字符串得到其原本字符串
在开发企业微信电子发票之拉取电子发票接口的时候,微信服务器会发送给我们一个2层的转义字符串,而我们要想得到我们想要的结果,就需要进行一些处理: 反转义+去除首尾双引号. 一.需求 现有一个字符串 st ...
- 收集—— css实现垂直居中
Method1: 在父元素上设置display:table-cell;vertical-align:middle(父元素不能设置浮动) Method2: 使用flex:父元素设置成display: f ...
- 配置mysql为主主复制步骤
mysql版本:mysql-5.6.24-solaris10-sparc-64bit.tar 操作系统:solaris 11g u10 操作用户:使用非root进行操作安装,a路服务器ip地址为192 ...
- 聊聊keep-alive组件的使用及其实现原理
写在前面 因为对Vue.js很感兴趣,而且平时工作的技术栈也是Vue.js,这几个月花了些时间研究学习了一下Vue.js源码,并做了总结与输出. 文章的原地址:https://github.com/a ...
- [转载] 常用 Java 静态代码分析工具的分析与比较
转载自http://www.oschina.net/question/129540_23043 简介: 本文首先介绍了静态代码分析的基本概念及主要技术,随后分别介绍了现有 4 种主流 Java 静态代 ...
- Python中文
在python中有两种默认的字符串:str和unicode.在Python中一定要注意区分"Unicode字符串"和"Unicode对象"的区别. 后面所有的& ...
- Struts2-052验证脚本
下面分享一下Struts2-052验证的python脚本 #-*- coding:utf-8 -*- import requests url_list_path ="/home/d0ll4r ...