首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

PopupWindow兑现弹出窗口

2012-09-01 
PopupWindow实现弹出窗口点击ListView的每一个item,将弹出窗口显示item详情主要代码:private void openPop

PopupWindow实现弹出窗口
点击ListView的每一个item,将弹出窗口显示item详情

主要代码:

private void openPopupwin() {LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);ViewGroup rootView = (ViewGroup) mLayoutInflater.inflate(R.layout.person_info_pop, null, true);TextView person_popup_name = (TextView)rootView.findViewById(R.id.person_popup_name);TextView person_popup_realName = (TextView)rootView.findViewById(R.id.person_popup_realName);TextView person_popup_age = (TextView)rootView.findViewById(R.id.person_popup_age);TextView person_popup_birthday = (TextView)rootView.findViewById(R.id.person_popup_birthday);TextView person_popup_phone = (TextView)rootView.findViewById(R.id.person_popup_phone);TextView person_popup_deptId = (TextView)rootView.findViewById(R.id.person_popup_deptId);Button btn_popup_close = (Button)rootView.findViewById(R.id.btn_popup_close);ImageView person_popup_head = (ImageView)rootView.findViewById(R.id.person_popup_head);try {person_popup_name.setText(selectedperson.getString("name"));person_popup_realName.setText(selectedperson.getString("realName"));person_popup_age.setText(selectedperson.getString("age"));person_popup_birthday.setText(selectedperson.getString("birthday"));person_popup_phone.setText("13880012450");//还未添加字段person_popup_deptId.setText("产品事业部");person_popup_head.setBackgroundDrawable(ImageUtil.geRoundDrawableFromUrl(HttpUtil.BASE_URL+selectedperson.getString("headPhotoPath"), 10));} catch (JSONException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();}popupWindow = new PopupWindow(rootView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, true);popupWindow.setBackgroundDrawable(new BitmapDrawable());popupWindow.setAnimationStyle(R.style.PopupAnimation);popupWindow.showAtLocation(root, Gravity.CENTER | Gravity.CENTER, 0, 0);popupWindow.update();btn_popup_close.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {popupWindow.dismiss();}});}

弹出窗口布局文件:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content" android:gravity="center"android:layout_height="wrap_content" android:layout_gravity="center" android:padding="5.0dip" android:layout_margin="5.0dip"android:background="@drawable/popup_corner"><RelativeLayout android:id="@+id/popup_top_bar" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:layout_height="wrap_content"><TextView android:text="用户详细信息" android:textColor="#760606" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16.0sp" android:layout_alignParentLeft="true"/><Button android:id="@+id/btn_popup_close" android:background="@drawable/popup_close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true"/></RelativeLayout><ImageView android:id="@+id/person_popup_head" android:scaleType="fitXY" android:layout_marginTop="5.0dip" android:layout_below="@id/popup_top_bar" android:layout_width="120.0dip" android:layout_height="120.0dip"/><TableLayout android:id="@+id/person_form" android:layout_marginLeft="2.0dip" android:layout_marginTop="5.0dip" android:layout_toRightOf="@id/person_popup_head" android:layout_below="@id/popup_top_bar" android:layout_width="wrap_content" android:layout_height="wrap_content"><TableRow ><TextView android:layout_width="60.0dip" android:gravity="right" android:textColor="#074f92" android:layout_height="wrap_content" android:text="账号:"/><TextView android:id="@+id/person_popup_name" android:textColor="#074f92" android:layout_marginLeft="15.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/></TableRow><TableRow ><TextView android:layout_width="60.0dip" android:gravity="right" android:textColor="#074f92" android:layout_height="wrap_content" android:text="姓名:"/><TextView android:id="@+id/person_popup_realName" android:textColor="#074f92" android:layout_marginLeft="15.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/></TableRow><TableRow ><TextView android:layout_width="60.0dip" android:gravity="right" android:textColor="#074f92" android:layout_height="wrap_content" android:text="年龄:"/><TextView android:id="@+id/person_popup_age" android:textColor="#074f92" android:layout_marginLeft="15.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/></TableRow><TableRow ><TextView android:layout_width="60.0dip" android:gravity="right" android:textColor="#074f92" android:layout_height="wrap_content" android:text="生日:"/><TextView android:id="@+id/person_popup_birthday" android:textColor="#074f92" android:layout_marginLeft="15.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/></TableRow><TableRow ><TextView android:layout_width="60.0dip" android:gravity="right" android:textColor="#074f92" android:layout_height="wrap_content" android:text="电话号码:"/><TextView android:id="@+id/person_popup_phone" android:textColor="#074f92" android:layout_marginLeft="15.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:autoLink="phone"/></TableRow><TableRow ><TextView android:layout_width="60.0dip" android:gravity="right" android:textColor="#074f92" android:layout_height="wrap_content" android:text="部门:"/><TextView android:id="@+id/person_popup_deptId" android:textColor="#074f92" android:layout_marginLeft="15.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content"/></TableRow></TableLayout></RelativeLayout>

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

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

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

1 楼 zhenzxie 2011-10-10     请问,,那些xml中<set><shape>等在哪里可以查阅到。。我是新学习android的,还不太了解这方面。。 2 楼 helloandroid 2011-10-11   zhenzxie 写道  请问,,那些xml中<set><shape>等在哪里可以查阅到。。我是新学习android的,还不太了解这方面。。
APIDEMo里面的View下面有很多这方面的例子 3 楼 zhenzxie 2011-10-11   谢谢。。有空去研究一下。

热点排行