`
yunshangbuhe
  • 浏览: 228935 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

popUPwindow

XML 
阅读更多
在程序里弹出一个小窗口,像系统的MediaController一样,具体做法:先在mail.xml的layout布局里加一个id,这个到后面会用到的,

1 <?xml version="1.0" encoding="utf-8"?>2  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"3     android:orientation="vertical"4     android:layout_width="fill_parent"5     android:layout_height="fill_parent"6     android:id="@+id/linear"<!--这个一定要加-->7     >接着布局文件里写一个control.xml文件,里面放一些要显示的widget,

1 <?xml version="1.0" encoding="utf-8"?> 2  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:orientation="vertical" 4     android:layout_width="fill_parent" 5     android:layout_height="fill_parent" 6     android:gravity="center" 7     android:background="#00000000" 8     > 9     <LinearLayout10         android:orientation="horizontal"11         android:layout_width="fill_parent"12         android:layout_height="wrap_content"13         android:gravity="center_horizontal"14         android:layout_marginTop="5dip"15         android:layout_marginBottom="5dip"16         >17         <ImageButton18         android:id="@+id/sounddown"19         android:layout_width="wrap_content"20         android:layout_height="wrap_content"21         android:src="@drawable/sounddown"22         />23         24         <TextView25         android:id="@+id/textNow"26         android:layout_width="wrap_content"27         android:layout_height="wrap_content"28         android:textSize="20sp"29         android:text="     "30         />31         <SeekBar32         android:id="@+id/seekbar"33         android:layout_width="500dip"34         android:layout_height="wrap_content"35         android:max="10000"36         />37         <TextView38         android:id="@+id/textAll"39         android:layout_width="wrap_content"40         android:layout_height="wrap_content"41         android:textSize="20sp"42         android:text="     "43         />44         <ImageButton45         android:id="@+id/soundup"46         android:layout_width="wrap_content"47         android:layout_height="wrap_content"48         android:src="@drawable/soundup"49         />50         </LinearLayout>51       <LinearLayout52       android:orientation="horizontal"53       android:layout_width="fill_parent"54       android:layout_height="wrap_content"55       android:gravity="center_horizontal"56       android:background="#0000003D" 57        >58        59        </LinearLayout>60     61     </LinearLayout>最后就是java文件,

 1 public class MainActivity extends Activity { 2     /** Called when the activity is first created. */ 3     private Button show; 4     public PopupWindow mPopupWindow; 5     private boolean boo=true; 6     @Override 7     public void onCreate(Bundle savedInstanceState) { 8         super.onCreate(savedInstanceState); 9         setContentView(R.layout.main);10         show = (Button) findViewById(R.id.button);11         show.setOnClickListener(new Button.OnClickListener(){12 13             @Override14             public void onClick(View v) {15                 // TODO Auto-generated method stub16                  if(boo){17                     boo=false;18                     check();19                     mPopupWindow.showAtLocation(findViewById(R.id.linear), Gravity.RIGHT|Gravity.BOTTOM, 0,0);20                 }else{21                     boo=true;22                     mPopupWindow.dismiss();23                 }24                 25             }});26     }27 28     private void check(){29         if(mPopupWindow==null){30             mPopupWindow=new PopupWindow(getLayoutInflater().inflate(R.layout.controler, null),LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);31         }32         if(mPopupWindow.isShowing()){33             mPopupWindow.dismiss();34         }35     }36 }
如果要响应PopupWindow里的widget,可以用LayoutInflater过滤xml文件,再用View view=getLayoutInflater().inflate(resource, root);就可以了。
分享到:
评论

相关推荐

    PopupWindow

    PopupWindow是Android系统中一个非常重要的UI组件,它允许开发者在屏幕任意位置显示一个浮动的窗口,这个窗口可以是对话框、菜单或者其他自定义视图。在Android应用开发中,PopupWindow常用于创建弹出式菜单、提示...

    PopupWindow监听返回键

    PopupWindow是Android开发中一个非常实用的组件,它允许开发者创建弹出式窗口,通常用于显示临时信息或者提供额外的功能选项。在某些场景下,我们可能希望PopupWindow能够响应系统的返回键事件,以便在用户按下返回...

    android popupwindow 底部灰色背景

    在Android开发中,PopupWindow是一个非常实用的组件,它允许我们创建浮动窗口,可以在Activity的任何位置显示。在实现特定的UI设计时,比如底部弹出菜单或对话框,我们可能会遇到需要添加底部灰色背景的需求。这个...

    PopupWindow之显示顶层对话框代码

    PopupWindow是Android开发中一个非常重要的组件,它允许开发者创建可弹出的窗口,通常用于显示临时信息或者作为上下文菜单。在Android应用设计中,PopupWindow可以为用户提供直观、便捷的交互方式,比如在主界面之上...

    popupwindow实现按钮下方阴影

    在Android开发中,PopupWindow是一种常用的轻量级弹窗组件,用于在屏幕任意位置显示一个浮层视图。本文将详细讲解如何实现标题所描述的功能:“popupwindow弹窗实现点击按钮,下方弹出popwindow,并且只是按钮下方有...

    Android从屏幕底部弹出PopupWindow

    在Android开发中,PopupWindow是一种常用的UI组件,它可以在屏幕上的任意位置显示一个浮动窗口,通常用于实现类似下拉菜单、提示框等效果。在这个场景中,我们要实现的是从屏幕底部弹出的PopupWindow,并带有滑动...

    仿微信右上角弹出PopupWindow

    在Android开发中,`PopupWindow`是一个非常实用的组件,常用于实现各种临时显示的弹出界面,如下拉菜单、浮动提示等。本Demo旨在模仿微信应用中的右上角弹出功能,提供一个类似的用户体验。我们将深入探讨如何创建和...

    Android源码——PopupWindow实现弹出菜单.zip

    在Android开发中,`PopupWindow` 是一个非常重要的组件,常用于实现各种弹出式菜单、下拉选择器等交互效果。本资料包"Android源码——PopupWindow实现弹出菜单.zip"主要聚焦于如何利用`PopupWindow`来创建自定义的弹...

    让popupwindow显示在view的上方并与该view水平居中对齐

    PopupWindow是Android开发中一个非常实用的组件,它允许我们创建一种浮动的窗口,通常用于显示临时信息或者快捷操作菜单。在Android应用设计中,有时我们需要让PopupWindow出现在某个特定View的上方,并与该View水平...

    PopupWindow测试demo(解决PopupWindow被输入法弹上去之后无法恢复原位问题)

    PopupWindow是Android开发中一个非常实用的组件,它允许开发者创建弹出式窗口,通常用于在主界面之上显示一些临时信息或提供附加操作。在标题提及的问题中,“PopupWindow被输入法弹上去之后无法恢复原位”是一个...

    android自定义通用PopupWindow

    在Android开发中,`PopupWindow` 是一个非常实用的组件,它允许我们创建弹出式窗口,用于显示一些临时信息或者交互操作。本教程将详细讲解如何封装一个通用的`PopupWindow`,以便在项目中复用,降低代码冗余,提高...

    窗帘式 从上往下弹出popupwindow带遮罩

    在Android开发中,PopupWindow是一种常用的轻量级窗口组件,用于在主界面之上弹出一个临时的视图,常用于实现下拉菜单、提示框等效果。本篇将详细讲解如何实现“窗帘式从上往下弹出的PopupWindow带遮罩”的功能。 ...

    安卓popupwindow相关-仿微信popupwindow.zip

    在安卓开发中,PopupWindow是一个非常实用的组件,它能够以弹出窗口的形式展示内容,类似于iOS中的ActionSheet。在本资源"安卓popupwindow相关-仿微信popupwindow.zip"中,开发者提供了一种模仿微信应用内...

    封装PopupWindow(1)

    PopupWindow是Android开发中常用的一种组件,用于在主界面之上显示一个临时的窗口,通常用于实现下拉菜单、提示信息等效果。在这个“封装PopupWindow(1)”中,我们将探讨如何对PopupWindow进行高效且可复用的封装,...

    Android PopupWindow实现右侧、左侧和底部弹出菜单

    在Android开发中,PopupWindow是一个非常实用的组件,它可以用来创建各种形式的浮动窗口,比如在屏幕边缘弹出的菜单。本教程将详细介绍如何利用PopupWindow实现右侧、左侧和底部弹出菜单,以提供丰富的交互体验。 ...

    android自定义popupwindow仿微信右上角弹出菜单效果

    在Android开发中,`PopupWindow` 是一个非常实用的组件,它可以用来创建各种弹出式菜单或对话框。本文将详细介绍如何使用`PopupWindow`在Android应用中模仿微信右上角的弹出菜单效果。 首先,我们需要理解`...

    Android下打造通用便捷的PopupWindow弹窗库

    在Android开发中,PopupWindow是一个常用的组件,它允许开发者创建浮动、可自定义的视图,通常用于实现下拉菜单、提示信息等效果。本文将深入探讨如何在Android环境中构建一个通用且便捷的PopupWindow库,提升应用的...

Global site tag (gtag.js) - Google Analytics