android 底部弹出菜单(带透明背景)
来源:互联网 发布:mac版练字打字软件 编辑:程序博客网 时间:2024/05/16 23:57
来源:http://blog.csdn.net/top_code/article/details/10285997#comments
最近项目中需要在界面的底部弹出一个向上弹出的菜单界面,并且带渐变的透明背景,跟大家分享一下!
运行效果图:
点击 分享 弹出 底部菜单
菜单界面 share_popup_menu.xml
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/transparent_bg" >
- <LinearLayout
- android:id="@+id/ll_popup"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:background="@color/popup_bg"
- android:orientation="vertical" >
- <RelativeLayout
- android:id="@+id/rl_weixin"
- android:layout_width="fill_parent"
- android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp"
- android:layout_height="@dimen/detail_menu_item_height"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="@dimen/detail_menu_margin_top_up"
- android:background="@color/light_black" >
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:src="@drawable/icon_wechat"
- android:layout_toLeftOf="@+id/tv_weixin"
- android:contentDescription="@string/app_name"/>
- <TextView
- android:id="@+id/tv_weixin"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:layout_marginLeft="15dp"
- android:text="@string/share_to_weixin"
- android:textColor="@color/white" />
- </RelativeLayout>
- <RelativeLayout
- android:id="@+id/rl_weibo"
- android:layout_width="fill_parent"
- android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp"
- android:layout_height="@dimen/detail_menu_item_height"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="@dimen/detail_menu_margin_top_up"
- android:background="@color/light_black" >
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:src="@drawable/icon_weibo"
- android:layout_toLeftOf="@+id/tv_weibo"
- android:contentDescription="@string/app_name"/>
- <TextView
- android:id="@+id/tv_weibo"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:layout_marginLeft="15dp"
- android:text="@string/share_to_weibo"
- android:textColor="@color/white" />
- </RelativeLayout>
- <RelativeLayout
- android:id="@+id/rl_duanxin"
- android:layout_width="fill_parent"
- android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp"
- android:layout_height="@dimen/detail_menu_item_height"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="@dimen/detail_menu_margin_top_up"
- android:background="@color/light_black" >
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:src="@drawable/icon_message"
- android:layout_toLeftOf="@+id/tv_duanxin"
- android:contentDescription="@string/app_name"/>
- <TextView
- android:id="@+id/tv_duanxin"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:layout_marginLeft="15dp"
- android:text="@string/share_to_duanxin"
- android:textColor="@color/white" />
- </RelativeLayout>
- <Button
- android:id="@+id/bt_cancle"
- android:layout_width="fill_parent"
- android:layout_marginLeft="20dp"
- android:layout_marginRight="20dp"
- android:layout_height="@dimen/detail_menu_item_height"
- android:layout_gravity="center"
- android:layout_marginBottom="@dimen/detail_menu_margin_top"
- android:layout_marginTop="@dimen/detail_menu_margin_top"
- android:background="@color/dark_white"
- android:text="@string/cancel"
- android:textColor="@color/white" />
- </LinearLayout>
- </RelativeLayout>
主界面MainActivity.java
[java] view plain copy
- package com.example.popupdemo;
- import android.app.Activity;
- import android.graphics.drawable.BitmapDrawable;
- import android.os.Bundle;
- 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.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.PopupWindow;
- import android.widget.RelativeLayout;
- public class MainActivity extends Activity implements OnClickListener {
- private PopupWindow mpopupWindow;
- private Button bt_share;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- findView();
- }
- private void findView() {
- bt_share = (Button) findViewById(R.id.bt_share);
- bt_share.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.bt_share:
- showPopMenu();
- break;
- case R.id.rl_weixin:
- mpopupWindow.dismiss();
- break;
- case R.id.rl_weibo:
- mpopupWindow.dismiss();
- break;
- case R.id.rl_duanxin:
- mpopupWindow.dismiss();
- break;
- case R.id.bt_cancle:
- mpopupWindow.dismiss();
- break;
- default:
- break;
- }
- }
- private void showPopMenu() {
- View view = View.inflate(getApplicationContext(), R.layout.share_popup_menu, null);
- RelativeLayout rl_weixin = (RelativeLayout) view.findViewById(R.id.rl_weixin);
- RelativeLayout rl_weibo = (RelativeLayout) view.findViewById(R.id.rl_weibo);
- RelativeLayout rl_duanxin = (RelativeLayout) view.findViewById(R.id.rl_duanxin);
- Button bt_cancle = (Button) view.findViewById(R.id.bt_cancle);
- rl_weixin.setOnClickListener(this);
- rl_weibo.setOnClickListener(this);
- rl_duanxin.setOnClickListener(this);
- bt_cancle.setOnClickListener(this);
- view.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- mpopupWindow.dismiss();
- }
- });
- view.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in));
- LinearLayout ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);
- ll_popup.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.push_bottom_in));
- if(mpopupWindow==null){
- mpopupWindow = new PopupWindow(this);
- mpopupWindow.setWidth(LayoutParams.MATCH_PARENT);
- mpopupWindow.setHeight(LayoutParams.MATCH_PARENT);
- mpopupWindow.setBackgroundDrawable(new BitmapDrawable());
- mpopupWindow.setFocusable(true);
- mpopupWindow.setOutsideTouchable(true);
- }
- mpopupWindow.setContentView(view);
- mpopupWindow.showAtLocation(bt_share, Gravity.BOTTOM, 0, 0);
- mpopupWindow.update();
- }
- }
渐变动画
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <alpha xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="400"
- android:fromAlpha="0.0"
- android:toAlpha="1.0" />
位移动画
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <translate xmlns:android="http://schemas.android.com/apk/res/android"
- android:duration="400"
- android:fromYDelta="100%"
- android:interpolator="@android:anim/decelerate_interpolator"
- android:toYDelta="0" />
代码大家自己下载下来慢慢看吧
工程下载地址:http://download.csdn.net/detail/fx_sky/6006143
0 0
- android 底部弹出菜单(带透明背景)
- android 底部弹出菜单(带透明背景)
- android 底部弹出选项,背景透明,PopupWindow的使用
- android底部弹出菜单
- android 底部弹出菜单
- android 仿微信底部弹出菜单
- Android 实现底部弹出菜单
- Android 对话框弹出底部背景透明度调节
- android自定义dialog弹出框、透明背景
- Android 弹出PopupWindows背景变透明
- android开发 - 自定义 弹出 底部菜单
- Android DialogFragment实现底部弹出菜单效果
- android AlertDialog用作底部弹出菜单
- android PopupWindow底部弹出gridview菜单
- Android笔记__PopupWindow底部弹出自定义菜单
- android 页面底部弹出菜单(dialog)
- Android 带动画的底部弹出视图
- Android 带动画的底部弹出视图
- CocoaPods的安装和使用说明
- 百度地图多个描点
- 一二三
- 关于在Spring4 jdbctemplate 遇到的一些基本问题总结
- Centos7 源码安装 Apache
- android 底部弹出菜单(带透明背景)
- 迷宫的最短路径
- JS调用Envi Services Engine发布的影像处理服务
- 华为OJ 初级 挑7
- Java OCR 图像智能字符识别技术[可识别中文]
- 软件定义存储(SDS)学习一
- 【疑问】:phpmyadmin修改root的问题
- 拆解Cluene系列(10)——详解索引的合并(一)
- java枚举使用详解