2011.07.05(2)——— android PopupWindow

参考:http://www.eoeandroid.com/thread-48051-1-1.html
http://disanji.net/2010/12/08/android-popupwindow-2/
http://www.iteye.com/topic/604462

1、新写一个layout文件 作为popupwindow的布局文件
<?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="fill_parent"     android:layout_height="fill_parent"      android:orientation="vertical"    android:gravity="center"    android:background="#c0000000">     <LinearLayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"      android:orientation="vertical"    android:gravity="center"    android:background="@drawable/popupwindow">     <LinearLayout     android:layout_width="fill_parent"          android:layout_height="wrap_content"        android:gravity="center"        android:layout_margin="5dip">            <TextView     android:text="课程:"    android:layout_width="wrap_content"         android:layout_height="wrap_content"    />     <EditText     android:id="@+id/popupwindow_class"          android:layout_width="200dip"         android:layout_height="wrap_content"        />    </LinearLayout>    <LinearLayout     android:layout_width="fill_parent"          android:layout_height="wrap_content"         android:gravity="center">          <Button         android:text="添加"         android:id="@+id/popupwindow_add"              android:layout_width="wrap_content"             android:layout_height="wrap_content">       </Button>          <Button         android:text="取消"         android:id="@+id/prpupwindow_cancel"              android:layout_width="wrap_content"             android:layout_height="wrap_content">      </Button>      </LinearLayout>      </LinearLayout></LinearLayout> 


2、布局文件当中 android:background="@drawable/popupwindow" 的边框圆角背景

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"        android:shape="rectangle">        <gradient         android:startColor="#c0000000"         android:endColor="#c0000000"            android:angle="90" /><!--背景颜色渐变 -->        <stroke         android:dashWidth="2dp"         android:dashGap="2dp"            android:width="2dp"             android:color="#FF00ff00"></stroke>        <!--描边 -->        <corners         android:bottomRightRadius="5dp"            android:bottomLeftRadius="5dp"             android:topLeftRadius="5dp"            android:topRightRadius="5dp" /><!--设置圆角--></shape>


3、显示popupwindow时的动态效果
res/anim/popuwindow.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator"        android:fromXScale="0.0"         android:toXScale="1.0"         android:fromYScale="0.0"        android:toYScale="1.0"         android:pivotX="50%"         android:pivotY="50%"        android:fillAfter="true"         android:duration="3000" /> <alpha         android:fromAlpha="0.0"         android:toAlpha="1.0"         android:duration="3000" /></set>


4、代码
/**     * 添加课程的popupwindow     * @param v     */    private void initPopupWindow(View v){        final View view = this.getLayoutInflater().inflate(R.layout.popupwindow, null);        popupWindow = new PopupWindow(view, LayoutParams.FILL_PARENT,                LayoutParams.FILL_PARENT, true);        Button btnOK=(Button)view.findViewById(R.id.popupwindow_add);        btnOK.setOnClickListener(new OnClickListener(){            public void onClick(View v) {                EditText et=(EditText)view.findViewById(R.id.popupwindow_class);                。。。。。。//一些处理        });       //Cancel按钮及其处理事件        Button btnCancel=(Button)view.findViewById(R.id.prpupwindow_cancel);        btnCancel.setOnClickListener(new OnClickListener(){            public void onClick(View v) {                popupWindow.dismiss();//关闭            }        });        popupWindow.setBackgroundDrawable(new BitmapDrawable());        popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);        popupWindow.setAnimationStyle(R.anim.popupwindow);            }

更多相关文章

  1. Android内核的根文件系统
  2. Android 常用布局
  3. android获取文件目录
  4. Android代码实现APK文件的安装与卸载
  5. Android:解决列表滚动时背景色变黑的方法
  6. Android 文件实现断点上传
  7. Android 存储方式之文件存储
  8. 时钟控件布局

随机推荐

  1. 问题资源Android(安卓)lint 能够做的事情
  2. 【转】android中onMeasure初看,深入理解
  3. Android(安卓)基础 MaterialButton
  4. Android(安卓)- 隐藏最顶端的通知条(Top
  5. 工欲善其事,必先利其器 -- Mac 软件推荐(序
  6. Android屏幕大小自适应
  7. android ImageView 圆角控件 设置上下左
  8. Phonegap+Android+Sencha touch开发应用(
  9. Android(安卓)横屏切换竖屏Activity的生
  10. android2.3 api demo 学习系列(21)--App/No