Android仿Iphone屏幕底部弹出半透明PopupWindow效果
作者:lfdfhl 发布时间:2023-08-17 06:14:43
标签:Android,Iphone,底部弹出,PopupWindow
本文实例为大家分享了Android仿Iphone屏幕底部弹出效果的具体代码,供大家参考,具体内容如下
main.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/button"
android:text="popupWindow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
styles.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="popupAnimation" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/in</item>
<item name="android:windowExitAnimation">@anim/out</item>
</style>
</resources>
popupwindow.xml如下:
<?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="#b5555555" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="12dip"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:orientation="vertical" >
<Button
android:id="@+id/confirmButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="确定"/>
<Button
android:id="@+id/cancleButton"
android:layout_marginTop="12dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="取消" />
</LinearLayout>
</RelativeLayout>
in.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="5000"
android:toYDelta="0"
android:duration="1500"
/>
</set>
out.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0"
android:toYDelta="5000"
android:duration="1500"
/>
</set>
PopupWindowTestActivity.Java如下:
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.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
/**
* Demo描述:
* 仿Iphone从屏幕底部弹出半透明的PopupWindow
*/
public class PopupWindowTestActivity extends Activity {
private Button button;
private Button confirmButton;
private Button cancleButton;
private PopupWindow popupWindow;
private View popupWindowView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
button=(Button) findViewById(R.id.button);
button.setOnClickListener(new ButtonOnClickListener());
}
private class ButtonOnClickListener implements OnClickListener {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
popupWindowView = inflater.inflate(R.layout.popupwindow, null);
popupWindow = new PopupWindow(popupWindowView,LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//设置PopupWindow的弹出和消失效果
popupWindow.setAnimationStyle(R.style.popupAnimation);
confirmButton = (Button) popupWindowView.findViewById(R.id.confirmButton);
confirmButton.setOnClickListener(new ButtonOnClickListener());
cancleButton = (Button) popupWindowView.findViewById(R.id.cancleButton);
cancleButton.setOnClickListener(new ButtonOnClickListener());
popupWindow.showAtLocation(confirmButton, Gravity.CENTER, 0, 0);
break;
case R.id.confirmButton:
System.out.println("点击了确定按钮");
break;
case R.id.cancleButton:
popupWindow.dismiss();
break;
default:
break;
}
}}
}


猜你喜欢
- 1.UUID 简介UUID 含义是通用唯一识别码 (Universally Unique Identifier),这是一个软件建构的标准。也
- Java 爬虫工具Jsoup详解Jsoup是一款 Java 的 HTML 解析器,可直接解析某个 URL 地址、HTML 文本内
- 目录一、定义联合(union)二、初始化联合(union)三、联合体变量的声明四、联合体变量的赋值和使用五、struct和union和区别u
- 介绍上图就是循环依赖的三种情况,虽然方式不同,但是循环依赖的本质是一样的,就A的完整创建要依赖与B,B的完整创建要依赖于A,相互依赖导致没办
- 具体代码如下所示:public class Parent { public static int a = parentStati
- 目录1 CompletionService介绍2 CompletionService源码分析3 CompletionService实现任务4
- 前言本来没有计划这一篇文章的,只是在看完SpringBoot核心原理后,突然想到之前开发中遇到的MVC自动失效的问题,虽然网上有很多文章以及
- 问题在Android开发中,遇到一个问题,是ListView嵌套GridView,需要点击整个ListView的Item进行跳转。但是在点击
- 这个比较简单,但是刚用as不久的朋友可能不知道。这里也不啰嗦了,给两张图就全懂了按ctrl+alt+s打开设置面板选择 Version &n
- 在springboot项目中如果要在不集成templates的情况下访问静态资源需要做以下配置1.在项目的application.yml文件
- 这篇文章主要介绍了Spring Bean初始化及销毁多种实现方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值
- 二分法查找,顾名思义就是要将数据每次都分成两份然后再去找到你想要的数据,我们可以这样去想,二分法查找很类似与我们平时玩的猜价格游戏,当你报出
- 一、前言前一篇文章已经详细介绍了如何使用Xposed框架编写第一个微信插件:摇骰子和猜拳 * 本文继续来介绍如何使用Xposed框架编写第
- 前些日子在开发中用到了需要ScrollView嵌套GridView的情况,由于这两款控件都自带滚动条,当他们碰到一起的时候便会出问题,即Gr
- Android自定义控件属性详细介绍1. reference:参考某一资源ID。
- 前言当您使用LINQ来处理数据库时,这种体验是一种神奇的体验,对吗?你把数据库实体像一个普通的收集,使用Linq中像Where,Select
- 代码如下所示: public static Bitmap
- 正文 #方法一:使用string.Contains方法string.Contains是大小写敏感的,如果要用该方法来判断一个str
- System_Server进程运行在system server进程中的服务比较多,这是整个android框架的基础Native服务Surfa
- 我们经常看到使用了ViewPager的App,在每页上面都会有一个滑块来标志当前处于哪一页。在PagerView包里有android.sup