背景:
阅读新闻
Android用PopupWindow实现弹出菜单实例
[日期:2013-04-18] 来源:Linux社区 作者:Linux [字体:]
step1:新建项目PopWindow,并导入菜单项使用的图片到/res/drawable目录下


step2:设置应用的UI界面
a.应用的总体界面,main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/main"
    >
<Button  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/button"
    android:onClick="openPopWindow"
    />
</LinearLayout>
b.弹出菜单的界面,popwindow.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent" android:background="@drawable/rectangle">  <!-- 设置一个手绘的长方形背景 -->
 <GridView android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:numColumns="4"
  android:horizontalSpacing="10dp" android:verticalSpacing="10dp"
  android:id="@+id/gridView" />
</LinearLayout>
其中的android:background="@drawable/rectangle"是引用rectangle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
 <gradient android:startColor="#1DC9CD" android:endColor="#A2E0FB"
  android:angle="270" />
 <padding android:left="2dp" android:top="2dp" android:right="2dp"
  android:bottom="2dp" />
</shape>
Android Widget 桌面数字时钟(DigtalClockWidget)实例
相关资讯
		       
	
本文评论 查看全部评论 (0)
 尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯
