Android仿Iphone屏幕底部弹出半透明PopupWindow效果

发布时间 - 2026-01-11 02:16:56    点击率:

本文实例为大家分享了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;
  }

 }}
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# Android  # Iphone  # 底部弹出  # PopupWindow  # Android实现底部半透明弹出框PopUpWindow效果  # Android中设置组件半透明和透明的效果示例  # Android编程自定义圆角半透明Dialog的方法  # Android开发中Dialog半透明背景消失  # Android Menu半透明效果的开发实例  # Android实现在列表List中显示半透明小窗体效果的控件用法详解  # Android编程实现popupwindow弹出后屏幕背景变成半透明效果  # Android编程实现设置按钮背景透明与半透明及图片背景透明的方法  # Android4.4+ 实现半透明状态栏(Translucent Bars)  # 弹出  # 大家分享  # 具体内容  # 大家多多  # windowEnterAnimation  # item  # Animation  # anim  # match_parent 


相关栏目: 【 网站优化151355 】 【 网络推广146373 】 【 网络技术251813 】 【 AI营销90571


相关推荐: 如何快速查询网址的建站时间与历史轨迹?  Laravel如何发送系统通知?(Notification渠道示例)  如何快速生成高效建站系统源代码?  Laravel如何生成API文档?(Swagger/OpenAPI教程)  悟空识字如何进行跟读录音_悟空识字开启麦克风权限与录音  Laravel如何处理表单验证?(Requests代码示例)  如何快速查询网站的真实建站时间?  如何在企业微信快速生成手机电脑官网?  如何在阿里云虚拟主机上快速搭建个人网站?  安克发布新款氮化镓充电宝:体积缩小 30%,支持 200W 输出  js实现点击每个li节点,都弹出其文本值及修改  猪八戒网站制作视频,开发一个猪八戒网站,大约需要多少?或者自己请程序员,需要什么程序员,多少程序员能完成?  Bootstrap整体框架之JavaScript插件架构  Laravel如何从数据库删除数据_Laravel destroy和delete方法区别  java ZXing生成二维码及条码实例分享  千库网官网入口推荐 千库网设计创意平台入口  Gemini手机端怎么发图片_Gemini手机端发图方法【步骤】  Laravel storage目录权限问题_Laravel文件写入权限设置  深圳网站制作培训,深圳哪些招聘网站比较好?  Midjourney怎样加参数调细节_Midjourney参数调整技巧【指南】  如何用好域名打造高点击率的自主建站?  怎样使用JSON进行数据交换_它有什么限制  详解Android——蓝牙技术 带你实现终端间数据传输  html5audio标签播放结束怎么触发事件_onended回调方法【教程】  JS实现鼠标移上去显示图片或微信二维码  教学论文网站制作软件有哪些,写论文用什么软件 ?  Laravel怎么使用Intervention Image库处理图片上传和缩放  千问怎样用提示词获取健康建议_千问健康类提示词注意事项【指南】  Laravel如何实现API版本控制_Laravel版本化API设计方案  音响网站制作视频教程,隆霸音响官方网站?  iOS中将个别页面强制横屏其他页面竖屏  JavaScript Ajax实现异步通信  javascript读取文本节点方法小结  Laravel如何使用Contracts(契约)进行编程_Laravel契约接口与依赖反转  北京专业网站制作设计师招聘,北京白云观官方网站?  如何使用 jQuery 正确渲染 Instagram 风格的标签列表  Laravel如何设置定时任务(Cron Job)_Laravel调度器与任务计划配置  Laravel如何发送系统通知_Laravel Notifications实现多渠道消息通知  如何在浏览器中启用Flash_2025年继续使用Flash Player的方法【过时】  Laravel如何使用Sanctum进行API认证?(SPA实战)  如何在万网开始建站?分步指南解析  canvas 画布在主流浏览器中的尺寸限制详细介绍  如何选择可靠的免备案建站服务器?  如何生成腾讯云建站专用兑换码?  如何在腾讯云服务器上快速搭建个人网站?  Laravel如何使用Spatie Media Library_Laravel图片上传管理与缩略图生成【步骤】  简单实现jsp分页  移动端脚本框架Hammer.js  Linux虚拟化技术教程_KVMQEMU虚拟机安装与调优  如何在云指建站中生成FTP站点?