欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2022-10-29 14:33:48
本文实例为大家分享了android仿iphone屏幕底部弹出效果的具体代码,供大家参考,具体内容如下 main.xml如下:

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

 }}
}

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