AndroidpopupWindow类似一个不能动的widget,它显示在别的View之上。

具体操作如下:

View

/layout/main.xml

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/main"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:gravity="center"

android:background="@color/background"

>

</LinearLayout>

要显示在PopupWindow上的View

<?xmlversion="1.0"encoding="utf-8"?>

/layout/extra.xml:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"android:layout_height="wrap_content"

android:orientation="vertical">

<ImageButtonandroid:id="@+id/cancel"android:layout_width="wrap_content"

android:layout_height="wrap_content"android:layout_gravity="top|right"

android:src="@drawable/del"android:layout_marginTop="10dip"

android:layout_marginRight="10dip"android:layout_marginBottom="10dip"

android:background="#0000003D"/>

<ScrollViewandroid:layout_width="wrap_content"

android:layout_height="wrap_content">

<TextViewandroid:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textSize="18dip"

android:text="欢迎使用AudioPlayer!\n\n

android:textColor="#99FFFFFF"

android:autoLink="email|web"/>

</ScrollView>

</LinearLayout>

代码实现:

ViewextralView=getLayoutInflater().Inflater(R.layout.extra,null);

PopupWindowextral=newPopupWindow(extralView);

接下来就是如何将这个extral触发显示出来,通常是用Button触发,但是也可以通过别的方式:

onCreate中加入

Looper.myQueue().addIdleHandler(newIdleHandler(){

publicbooleanqueueIdle(){

//TODOAuto-generatedmethodstub

if(extraWindow!=null){

extraWindow.showAtLocation(findViewById(R.id.main),Gravity.TOP,0,0);

extraWindow.update(0,25,ScreenWidth,60);

}

returnfalse;

}

});

ScreenWidth可以通过Diaplay得到。

在这里的IdleHandler是在后台处理消息的一种方式,当目前用户没有操作时触发。一般,当我们不需要人为触发时可以通过这种方式触发。

更多相关文章

  1. Android jni中数组参数的传递方式
  2. android 禁用锁屏 到修改方式
  3. android防止屏幕关闭后后台服务停止运行
  4. Android模拟点击的四种方式
  5. 关于Android 设置监听的的四种方式的理解
  6. 【Android应用开发】-(19)Android 串口编程原理和实现方式
  7. Android中工作线程与主线程同步方式
  8. Android 使用HTTP(get和post)方式登陆服务器
  9. android 创建 删除桌面快捷方式

随机推荐

  1. 百度笔试题
  2. Android(安卓)LazyList 从网络获取图片并
  3. android中action详解
  4. [转]android两次按返回键退出程序实现
  5. Android(安卓)百度地图开发之一(Hello Bai
  6. [置顶] Android ble低功耗蓝牙开发
  7. Android开发(一):Android(安卓)Studio及SD
  8. 论文翻译——DREBIN : Effective and Exp
  9. 检测Android中触摸屏手势的动作与坐标
  10. 使用Handler实现定时器