PopWindow动画实现底部滑出菜单

1.结构目录

2.实现步骤

1.主布局activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/open"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="打开泡泡窗口" />

</RelativeLayout>

2.popupwindow.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/gv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#00bfff"
        android:numColumns="4" >
    </GridView>

</LinearLayout>

3.MainActivity

public class MainActivity extends Activity implements OnClickListener {

	private Button open;
	private View parent;
	private View popView;
	private PopupWindow popupWindow;
	private GridView gv;

	private String[] names = { "生", "如", "夏", "花", "海", "阔", "天", "空" };
	private int[] images = { R.drawable.ic_launcher, R.drawable.ic_launcher,
			R.drawable.ic_launcher, R.drawable.ic_launcher,
			R.drawable.ic_launcher, R.drawable.ic_launcher,
			R.drawable.ic_launcher, R.drawable.ic_launcher };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		parent = findViewById(R.id.main);
		open = (Button) findViewById(R.id.open);
		open.setOnClickListener(this);
		initPopupWindow();
	}

	/**
	 * 初始化popupWindow
	 */
	private void initPopupWindow() {
		popView = getLayoutInflater().inflate(R.layout.popupwindow, null);
		popupWindow = new PopupWindow(popView,
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		popupWindow.setFocusable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setOutsideTouchable(true);
		gv = (GridView) popView.findViewById(R.id.gv);
		gv.setAdapter(MyAdapter());

	}

	/**
	 * 为GridView填充数据
	 *
	 * @return
	 */
	private ListAdapter MyAdapter() {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < names.length; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("names", names[i]);
			map.put("images", images[i]);
			list.add(map);
		}
		SimpleAdapter simpleAdapter = new SimpleAdapter(this, list,
				R.layout.pop_item, new String[] { "names", "images" },
				new int[] { R.id.tv, R.id.img });
		return simpleAdapter;
	}

	@Override
	public void onClick(View v) {
		//为popWindow添加动画效果
		popupWindow.setAnimationStyle(R.style.popWindow_animation);
		// 点击弹出泡泡窗口
		popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
	}
}

4.为了实现动画进出效果,定义两个布局文件

popupwindow_enter.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="500"
        android:fromYDelta="100%p"
        android:toYDelta="0" />

    <alpha
        android:duration="500"
        android:fromAlpha="0.5"
        android:toAlpha="1.0" />

</set>

5.popupwindow_exit.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:toAlpha="0.5" />

    <translate
        android:fromYDelta="0"
        android:toYDelta="100%p"
        android:duration="500" />

</set>

6.style.xml

 <style name="popWindow_animation">
        <item name="android:windowEnterAnimation">@anim/popupwindow_enter</item>
        <item name="android:windowExitAnimation">@anim/popupwindow_exit</item>
    </style>
时间: 2024-08-29 22:42:22

PopWindow动画实现底部滑出菜单的相关文章

常用的企业站滑出菜单效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

一款灰色风格的Css滑出菜单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

【转】微信中MMAlert(半透明底部弹出菜单)的使用介绍

原文地址:http://blog.csdn.net/singwhatiwanna/article/details/8892930 果大家时常用过微信或者用过iphone,就会发现有种从底部弹出的半透明菜单,这种菜单风格优美并且用户体验良好,先看一下效果. MMAlert来自微信开放平台的sdk示例,其示例的代码有点乱,我做了删减和整理,只保留了MMAlert这个类的一部分功能,即只保留了实现上述效果的那个函数,因为其他函数比较简单,就是普通的AlertDialog,我觉得大家都懂,所以直接删掉了

Android 长按Listview 每个item底部弹出菜单

android界面中,有一个功能是点击listview的每个item,下方弹出两个菜单,可以点击进入别的界面,这个功能可以使用开源项目expandablelistview,的确是可以实现,但发现导入的代码过多,显得很臃肿,经过师傅指点,我采用的是如下方法,步骤如下: 1.新建一个listview,需要在外层套一层scrollview,不过使用scrollview会导致listview的高度只有一个item,需要使用自定义的listview,代码如下: package allone.verbank

微信小程序之 动画 —— 自定义底部弹出层

wxml: <view class='buy' bindtap='showBuyModal'>立即购买</view> <!-- 点击立即购买 弹出购买遮罩层 --> <view class="cover_screen" bindtap="hideBuyModal" wx:if="{{showModalStatus}}"></view> <!-- 点击立即购买 弹窗 --> &

一款效果精致的 jQuery 多层滑出菜单插件

想要以用户友好的方式呈现多级菜单是件不容易的事情,而且还要跨浏览器兼容就更难了.Multi-Level Push Menu 这款 jQuery 插件提供了呈现这种菜单的解决方案,能够让你无限制的展示菜单,支持常用浏览器,而且能够用于触屏设备. 您可能感兴趣的相关文章 特色功能: 多级菜单支持: 导航元素可以无限制嵌套: 可以使用手势操作菜单: 支持向左和向右两个方向滑动: 简单.灵活的 HTML 标签: 提供了易于使用和扩展的 API: 跨浏览器兼容性: Chrome Midori Firefo

鼠标悬停时从底部滑出文字信息

1 //比较两种方式的不同,方式二会出现抖动的bug 2 3 $(document).ready(function(e) { 4 5 //方式一 6 $('#cont').hover ( function () { 7 $("#nav").animate({bottom: "0px"},150); 8 }, function () { 9 $("#nav").animate({bottom: "-50px"},150);; 1

Android开发笔记(一百零一)滑出式菜单

可移动页面MoveActivity 滑出式菜单从界面上看,像极了一个水平滚动视图HorizontalScrollView,当然也可以使用HorizontalScrollView来实现侧滑菜单.不过今天博主要说的是利用线性布局LinearLayout来实现,而且是水平方向上的线性布局. 可是LinearLayout作为水平展示时有点逗,因为如果下面有两个子视图的宽度都是match_parent,那么LinearLayout只会显示第一个子视图,第二个子视图却是怎么拉也死活显示不了.倘若在外侧加个H

iOS_21团购_顶部菜单和弹出菜单联动

最后效果图: 各控件关系图1: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >\ 各控件关系图2: 点击Dock上面的buttonDockItem, 创建经导航控制器包装的DealListController, 而且加入到主控制器的右側空间 // // Deal