popwindow 加个边框_PopupWindow仿微信浮层弹出框效果
最近公司项目需要实现类似微信的浮层弹出框。研究发现是用PopupWindow实现的。而且可以自定义位置以及出现和退出时的动画,由于太晚了就不实现动画了,需要得同学请自己研究下。由于本人新手其中的不足和缺点请见谅。
代码如下:
首先是定义顶部按钮的main.xml文件
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="@color/white" >
android:id="@+id/rl_action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dip"
android:background="@color/gold" >
android:id="@+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
android:background="@drawable/more" />
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:layout_toLeftOf="@+id/more"
android:background="@drawable/add"
/>
android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dip"
android:layout_toLeftOf="@+id/add"
android:background="@drawable/search"
/>
其次是定义弹出框PopupWindow的popupwindow_dialog.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/click"
android:cacheColorHint="#00000000"
android:orientation="vertical" >
android:id="@+id/lv_dialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:listSelector="@drawable/grouplist_item_bg_normal" >
接着是每一个弹出框显示的文字text.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/tv_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:padding="5dp"
android:textSize="20sp" />
最后是主界面的MainActivity.java
package com.bn.weixindemo;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
/**
*
*@title 标题
*@description 仿微信顶部弹出框的popuwindow
*@author zhengxiaolin
*@version 1.0
*@created 2014-5-23 上午12:11:11
*@changeRecord [修改记录]
*/
public class MainActivity extends Activity implements OnClickListener{
private Button mBtnMore,mBtnAdd,mBtnSearch;
private PopupWindow popupWindow;
private LinearLayout layout;
private ListView listView;
private String[] more = {"我的相册","我的收藏","我的银行卡","设置","意见反馈"};
private String[] add ={"发起群聊","添加朋友","视屏聊天","扫一扫","拍照分享"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBtnMore = (Button) findViewById(R.id.more);
mBtnAdd = (Button) findViewById(R.id.add);
mBtnSearch = (Button) findViewById(R.id.search);
setOnClickListener();
}
private void setOnClickListener() {
mBtnMore.setOnClickListener(this);
mBtnAdd.setOnClickListener(this);
mBtnSearch.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.more:
mBtnMore.getTop();
int y = mBtnMore.getBottom() * 3 / 2;
int x = getWindowManager().getDefaultDisplay().getWidth();
showMorePopupWindow(x, y);
break;
case R.id.add:
mBtnAdd.getTop();
int y1 = mBtnAdd.getBottom() * 3 / 2;
int x1 = getWindowManager().getDefaultDisplay().getWidth();
showAddPopupWindow(x1, y1);
break;
case R.id.search:
Toast.makeText(getBaseContext(), "搜索", 1).show();
default:
break;
}
}
public void showMorePopupWindow(int x, int y) {
layout = (LinearLayout) LayoutInflater.from(MainActivity.this).inflate(
R.layout.popupwindow_dialog, null);
listView = (ListView) layout.findViewById(R.id.lv_dialog);
listView.setAdapter(new ArrayAdapter(MainActivity.this,
R.layout.text, R.id.tv_text, more));
popupWindow = new PopupWindow(MainActivity.this);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow
.setWidth(getWindowManager().getDefaultDisplay().getWidth() / 2);
popupWindow.setHeight(420);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setContentView(layout);
popupWindow.showAtLocation(findViewById(R.id.main), Gravity.LEFT
| Gravity.TOP, x, y);//需要指定Gravity,默认情况是center.
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(getBaseContext(), "您选择了:"+more[arg2], 1).show();
popupWindow.dismiss();
popupWindow = null;
}
});
}
/**
* 点击+时弹出的popuwindow
*/
public void showAddPopupWindow(int x, int y) {
layout = (LinearLayout) LayoutInflater.from(MainActivity.this).inflate(
R.layout.popupwindow_dialog, null);
listView = (ListView) layout.findViewById(R.id.lv_dialog);
listView.setAdapter(new ArrayAdapter(MainActivity.this,
R.layout.text, R.id.tv_text, add));
popupWindow = new PopupWindow(MainActivity.this);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow
.setWidth(getWindowManager().getDefaultDisplay().getWidth() / 2);
popupWindow.setHeight(420);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setContentView(layout);
popupWindow.showAtLocation(findViewById(R.id.main), Gravity.LEFT
| Gravity.TOP, x, y);//需要指定Gravity,默认情况是center.
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(getBaseContext(), "您选择了:"+add[arg2], 1).show();
popupWindow.dismiss();
popupWindow = null;
}
});
}
}
好了,主要代码就完成了,实现效果如下所示
由于本人没有图片,所以弹出框的背景图没有处理,弹出框中的每一项的前面也没有添加图片,有需要得同学可以自行添加。(效果已经出来了,细节没有调整,请大家见谅)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
popwindow 加个边框_PopupWindow仿微信浮层弹出框效果相关推荐
- 非常漂亮的仿腾讯弹出层效果
2019独角兽企业重金招聘Python工程师标准>>> 非常漂亮的仿腾讯弹出层效果 http://www.jscode.cn/js/v45300 jquery弹出层插件-jquery ...
- js仿苹果风格弹出框alert插件
下载地址 js仿苹果风格弹出框alert插件,多种调用方式. dd:
- android 弹窗有边框_Android 多种简单的弹出框样式设置代码
简介 这是一个基于AlertDialog和Dialog这两个类封装的多种弹出框样式,其中提供各种简单样式的弹出框使用说明.同时也可自定义弹出框. 特性 1.使用链式开发代码简洁明了 2.所有的弹出框样 ...
- android中点击加号动画,android animation之scale 缩放(仿微信加号弹出菜单的动画效果)...
仿微信 +号 处理事件:弹出菜单的动画效果--缩放(反义词) 放大效果(缩小的代码只需将fromXScale和toXScale,:fromYScale和toYScale变换) android:inte ...
- popwindow 加个边框_popupWindow自定义(1)
1.自定义布局(密码框.对话框等等) 2.从下往上弹出效果的实现 一.对话框 第一步: Xml代码: xmlns:android="http://schemas.android.com/ap ...
- jquery 实现仿QQ右下角弹出框
js代码: <script type="text/javascript" src="script/jquery-1.3.1.min.js">< ...
- Android仿IOS地区弹出框选择器
一. 主代码 View view = dialogm(); final MyAlertDialog dialog1 = new MyAlertDialog( InvoiceActivity.this ...
- html自定义js程序,JS中微信小程序自定义底部弹出框
实现微信小程序底部弹出框效果,代码分为html,css和js两部分,具体代码详情大家参考下本文. html CSS .commodity_screen { width: 100%; height: 1 ...
- 好看的php提示弹窗,漂亮的jquery提示效果(仿腾讯弹出层)
超漂亮的仿腾讯弹出层效果 body {background: #ffffff; color: #444;} a{color: #09d; text-decoration: none;border: 0 ...
- Android自定义弹窗模仿微信,Android 仿微信朋友圈点赞和评论弹出框功能
本文简单模仿微信朋友圈的点赞和评论弹出框,布局等细节请忽略,着重实现弹出框.发评论,及弹出位置的控制. 1. 微信弹出框 微信朋友圈的点赞和评论功能,有2个组成部分: 点击左下角的"更多&q ...
最新文章
- 【原创】聊天+传送文件+设置字体及颜色(vs2010+mfc开发)
- Windows Print Spooler服务最新漏洞CVE-2021-34527详细分析
- PHP 字符串与数组间的相互转化
- java基础--java.util.Date类型小结
- 用例图中的Actor(参与者)一定是人吗?
- (3.5)HarmonyOS鸿蒙多按钮点击事件
- opencv 分割长度_opencv+python智能车道检测,助力无人驾驶
- s3c6410 uboot代码分析《二》
- NPS之Socks流量分析以及未授权复现
- 这五本热门网络小说,竟然三本在第四届橙瓜网络文学奖评选目前排在前五!
- matlab二重定积分_matlab 对于变限积分的计算,二重积分 三重积分
- 网络***的基础教程
- 小白必看:合理搭建巨量引擎账户结构要点总结!
- 安装Brat标记工具
- 数模【Mathematica(安装、入门方法、基本计算、基本图形、创建互动模型、利用数据、幻灯片演示、完整实例)】
- 告赢了!程序员拒绝春节带电脑回家工作被开除,判决获赔19.4万!
- 按键,触摸屏流程分析
- 使用react-cropper结合图片压缩方法对图片进行裁剪压缩处理
- Siebel Adapter在WMB上的应用
- 目录——Java趣味编程100例
热门文章
- comsol奶酪模型 comsol多孔材料
- 用Java写脚本,常用的一些方法
- 一个计算机爱好者的不完整回忆(十六)我的第一台电脑
- 微商城是什么?如何制作一个微商城
- 京东X无人超市布局瞄准加油站,下一个场景会在哪儿
- 解决天正M_批打印没有天正的打印格式(TArch20V6.ctb)的问题
- 后缀树(一)定义及构造
- 搭建IMXRT1020单片机开发环境(采用MCUXpressoIDE,包括安装SDK)
- python基于django的校园公寓宿舍报修管理系统设计与实现
- 华硕飞行堡垒Fx50j4200H 4600HD 黑苹果High Sierra10.13.6心得