上一篇以activity方式实现了弹出框效果,这一篇就以dialog方式实现
直接看布局代码:
<?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="wrap_content"
android:orientation="vertical"
android:background="@drawable/xiyouhui_title_dialog_bg" >
<ListView
android:id="@+id/ls_hdyy_dialogleft"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:divider="#ffffff"
android:dividerHeight="1dp"></ListView>
</LinearLayout>
不过多说明,看实现代码:
private void showLeftDialog(){ View view = LayoutInflater.from(this).inflate(R.layout.xyh_hdyy_dialogleft, null); WindowManager wm = this.getWindowManager(); int width = wm.getDefaultDisplay().getWidth(); //创建dialog实例,R.style.MyDialogStyleTop为样式,可以在其中加入动画效果,同上一篇activity的样式
dialogLeft.setContentView(view);dialogLeft.setCanceledOnTouchOutside(true); Window dialogWindow = dialogLeft.getWindow(); WindowManager.LayoutParams lp = dialogWindow.getAttributes(); dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP); lp.x = 0; // 新位置X坐标 lp.y = 110; // 新位置Y坐标 lp.width = (int) (width*0.5); // 宽度 lp.height = WindowManager.LayoutParams.WRAP_CONTENT; // 高度 dialogWindow.setAttributes(lp); listLeft.clear();Dialog dialogLeft = new Dialog(this,R.style.MyDialogStyleTop);
listLeft = getListData("ceoactivity");//list添加数据
listLeft.add("全部");
// ListView listViewDialogLeft = (ListView) view.findViewById(R.id.ls_hdyy_dialogleft);
// YuYueDialogAdapter adapterleft = new YuYueDialogAdapter(XiyouhuiHuoDongYuYueActivity.this, listLeft);
// listViewDialogLeft.setAdapter(adapterleft);
// listViewDialogLeft.setOnItemClickListener(onItemClickListenerLeft);
dialogLeft.show();
}
没有采用继承Dialog类的方式实现,直接在要显示的activity中添加dialog,并为此dialog添加view,然后通过WindowManager,定义dialog的位置