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;
  }

 }}
}

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

(0)

相关推荐

  • Android实现在列表List中显示半透明小窗体效果的控件用法详解

    本文实例讲述了Android实现在列表List中显示半透明小窗体效果的控件用法.分享给大家供大家参考,具体如下: Android 在列表List中显示半透明小窗体效果的控件,多的不多直接上代码,要说的都在注释里了: import com.hiapk.market.R; import android.content.Context; import android.graphics.PixelFormat; import android.os.Handler; import android.view

  • Android4.4+ 实现半透明状态栏(Translucent Bars)

    Android从4.4(KitKat) 开始进行了一些视觉上的改善和提升,其中包括让状态栏(Status Bar)和下方导航栏(Navigation Bar)进行半透明处理,可以使APP内容向上下延伸,使整个画面的利用度大幅度提升,本篇就来说说这个"半透明状态栏"(Translucent Bars). 简单做了个Demo效果如下图 *这里解释个误区,国内开发者和设计师经常把这种半透明效果称为沉浸式状态栏这是不对的, 沉浸式Immersive mode,官方解释为hiding all s

  • Android中设置组件半透明和透明的效果示例

    本文介绍了Android是如何设置组件半透明和透明的效果,分享出来供大家参考,下面来看看详细的介绍: 1.Button或者ImageButton的背景设为透明或者半透明 半透明 <Button android:background="#e0000000" ... /> 透明 <Button android:background="#00000000" ... /> 颜色和不透明度 (alpha) 值以十六进制表示法表示.任何一种颜色的值范围都

  • Android编程自定义圆角半透明Dialog的方法

    本文实例讲述了Android编程自定义圆角半透明Dialog的方法.分享给大家供大家参考,具体如下: 效果图如下: 只是在实例化的时候使用带样式的构造函数即可 new MyDialog(GameActivity.this, R.style.dialog); 在value文件夹中添加mydialogthemes.xml <?xml version="1.0″ encoding=" utf-8″?> <resources> <style name="

  • Android开发中Dialog半透明背景消失

    近日,遇到一个Dialog半透明背景消失的问题,背景需求是自定义Dialog实现警告提示框: // 初始化警告弹出框 alertDialog = new EmpAlertView(context, Utils.getIdByName(context, "style", "alert_style")); alertDialog.setCanceledOnTouchOutside(false); LayoutInflater inflater = (LayoutInfl

  • Android编程实现设置按钮背景透明与半透明及图片背景透明的方法

    本文实例讲述了Android编程实现设置按钮背景透明与半透明及图片背景透明的方法.分享给大家供大家参考,具体如下: Button或者ImageButton的背景设为透明或者半透明: 半透明 复制代码 代码如下: <Button android:background="#e0000000" ... /> 透明 复制代码 代码如下: <Button android:background="#00000000" ... /> 颜色和不透明度 (al

  • Android Menu半透明效果的开发实例

    不知道大家是否用过天天动听,对于它界面上的半透明Menu效果,笔者感觉非常漂亮.下面是天天动听半透明Menu的截图,欣赏下吧: 感觉还不错吧?那么如何实现这种半透明Menu效果呢?本文就重点讨论并给出这种Menu的具体代码实现过程. 首先分析下实现这种半透明Menu所需做的工作,并进行合理分解: 1.  利用Shaper设置一个半透明圆角背景. 2.  定义Menu布局,主要就GridView,把图标都放在这个GridView. 3.  Menu事件, 通过PopupWindow或者AlertD

  • Android编程实现popupwindow弹出后屏幕背景变成半透明效果

    本文实例讲述了Android编程实现popupwindow弹出后屏幕背景变成半透明效果的方法.分享给大家供大家参考,具体如下: android中popupwindow弹出后,屏幕背景变成半透明这个效果很普通.实现的方法也很多.我使用的可能是最简单的一种,就是设置一下getWindows的透明度.不多说上代码 /** * 设置添加屏幕的背景透明度 * @param bgAlpha */ public void backgroundAlpha(float bgAlpha) { WindowManag

  • Android实现底部半透明弹出框PopUpWindow效果

    Android底部半透明弹出框PopUpWindow,供大家参考,具体内容如下 layout布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" androi

  • 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仿微信进度弹出框的实现方法

    MainActivity: package com.ruru.dialogproject; import android.app.Activity; import android.os.Bundle; import android.view.View; public class MainActivity extends Activity implements Runnable { LoadingDialog dialog; @Override protected void onCreate(Bu

  • Android 仿苹果底部弹出Dialog

    style文件 <style name="ActionSheetDialogStyle" parent="@android:style/Theme.Dialog"> <!-- 背景透明 --> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:wind

  • Android仿IOS底部弹出对话框

    在Android开发过程中,常常会因为感觉Android自带的Dialog的样式很丑,项目开发过程中会影响整体效果,会使得开发过程很是忧伤....(话唠时间结束!) 本文我将介绍一款开源的Dialog仿IOS底部弹窗效果IOS_Dialog_Library的使用.我将通过几个简单的示例介绍IOS_Dialog_Library.zip的使用方法. 1.IOS_Dialog_Library是开源的Dialog框架,所以首先你得下载IOS_Dialog_Library.zip包,并作为Library引

  • PopupWindow仿微信浮层弹出框效果

    最近公司项目需要实现类似微信的浮层弹出框.研究发现是用PopupWindow实现的.而且可以自定义位置以及出现和退出时的动画,由于太晚了就不实现动画了,需要得同学请自己研究下.由于本人新手其中的不足和缺点请见谅. 代码如下: 首先是定义顶部按钮的main.xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.an

  • Android实现微博菜单弹出效果

    先上Android仿微博菜单弹出效果图,这个截图不是很流畅,大家可以下载apk试一下. 说一下实现思路: 1.截取当前窗口,对图片做高斯模糊处理,将处理后的图片做popupwindow的背景图片: 2.创建popupwindow,完成布局,这儿要注意:View的移动范围是由parent的大小决定的,就是只能在parent的范围内移动: 3.给买个View添加进入动画,每个比前一个延期50ms播放动画,关闭窗口时相反: 4.为View的动画添加回弹插值器: MoreWindow.java窗口 pa

  • Android Animation实战之屏幕底部弹出PopupWindow

    Android动画的一个实战内容,从屏幕底部滑动弹出PopupWindow. 相信这种效果大家在很多APP上都遇到过,比如需要拍照或者从SD卡选择图片,再比如需要分享某些东西时,大多会采用这么一种效果: 那这种效果如何实现呢? 我们仿写一个这种效果的实例吧: 1)我们首先定义一下,弹出窗口的页面布局组件:take_photo_pop.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout

  • Android自定义PopupWindow仿点击弹出分享功能

    本文实例自定义PopupWindow,点击弹出PopupWindow,背景变暗,仿点击弹出分享功能,供大家参考,具体内容如下 注:参照大神代码写的 自定义代码 package com.duanlian.popupwindowdemo; import android.app.Activity; import android.content.Context; import android.graphics.drawable.ColorDrawable; import android.view.Lay

  • Android自定义弹出窗口PopupWindow使用技巧

    PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 复制代码 代码如下: public PopupWindow(View contentView, int width, int height, boolean focusable) contentView为要显示的view,width和height为宽和高,值为像素值,也可以是MATCHT_PARENT和WRAP_CONTENT. focusable为是否可以获得焦点,这是一个很重要的参数

随机推荐