设为首页 加入收藏

TOP

Android PopUp window的使用
2014-11-24 11:47:47 来源: 作者: 【 】 浏览:1
Tags:Android PopUp window 使用

具体操作如下:


主View:


/layout/main.xml


< xml version="1.0" encoding="utf-8" >



android:id="@+id/main"


android:orientation="vertical"


android:layout_width="fill_parent"


android:layout_height="fill_parent"


android:gravity="center"


android:background="@color/background"


>



要显示在PopupWindow上的View:


< xml version="1.0" encoding="utf-8" >



/layout/extra.xml:



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


android:orientation="vertical">



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"/>



android:layout_height="wrap_content">



android:layout_height="wrap_content"


android:textSize="18dip"


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


android:textColor="#99FFFFFF"


android:autoLink="email|web"/>




代码实现:


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


PopupWindow extral = new PopupWindow(extralView);


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


在onCreate中加入


Looper.myQueue().addIdleHandler(new IdleHandler() {



public boolean queueIdle() {


// TODO Auto-generated method stub


if (extraWindow != null) {


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


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


}


return false;


}


});


ScreenWidth可以通过Diaplay得到。


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


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android4.0 输入法框架分析 下一篇Android4.0 Power、home、menu等..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·深入理解 Java 集合 (2025-12-27 07:22:48)
·Java集合框架全面解 (2025-12-27 07:22:45)
·时隔 15 年,巨著《J (2025-12-27 07:22:43)
·定义一个类模板并实 (2025-12-27 06:52:28)
·一文搞懂怎么用C语言 (2025-12-27 06:52:25)