1. 在适配器中的getItem方法中, 得到条目对应的view对象, 将结果返回给item的点击事件
2.给listview的item设置点击事件的监听
3.得到适配器中getItem方法返回的点击listItem对应的对象
4. 创建 popub窗体
5. 给popub窗体设置透明背景 注:如果 popub没有背景则设置不了动画效果
6.show出popubWindow
7.在activity销毁时,dismiss掉popubWindow
/**
* 1. 得到条目对应的view对象,结果返回给item的点击事件
*/
@Override
public
Object getItem(
int
position) {
//初始化化控件
if
(position==0){
return
null
;
}
else
if
(position==(
userAppList
.size()+1)){
return
null
;
}
else
if
(position<=
userAppList
.size()){
//从集合中得到用户应用
int
newPosition=position-1;
appInfoBean
=
userAppList
.get(newPosition);
}
else
{
int
newPosition=position-1-
userAppList
.size()-1;
appInfoBean
=
sysAppList
.get(newPosition);
}
return
appInfoBean
;
}
@Override
public
long
getItemId(
int
position) {
return
0;
}
}
//3.得到适配器中getItem方法返回的点击listItem对应的对象
Object obj=
lv_app_manage
.getItemAtPosition(position);
if
(obj!=
null
&& obj
instanceof
AppInfoBean){
clickAppInfo
=(AppInfoBean) obj;
//被点击item对应的对象
if
(
popubWindow
!=
null
&&
popubWindow
.isShowing()){
//再次点击时关闭已经存在的popubWindow
popubWindow
.dismiss();
popubWindow
=
null
;
}
View contentView=View.inflate(getApplicationContext(), R.layout.
pop_app_item
,
null
) ;
//4. 创建popub 窗体 contentView:填充的布局 -2,-2: 包裹内容
popubWindow
=
new
PopupWindow(contentView, -2, -2);
//5. 给popub 窗体设置透明背景 注:如果popub没有背景则设置不了动画效果
popubWindow
.setBackgroundDrawable(
new
ColorDrawable(Color.
TRANSPARENT
));
int
[] locations=
new
int
[2];
view.getLocationInWindow(locations);
//得到view对象在activity窗体上的位置的参数x,y
//6.show出popubWindow 1. popub所在的窗体 2.对其方式 3.距离activity窗体左边框的距离 4.距离activity窗体上边框的距离
popubWindow
.showAtLocation(parent, Gravity.
LEFT
+Gravity.
TOP
, 65, locations[1]);
//给popubWindow设置动画展示效果
ScaleAnimation scale=
new
ScaleAnimation(0.5f, 1.2f, 0.5f, 1.2f);
scale.setDuration(300);
contentView.startAnimation(scale);
}
}
/*
* 7.在activity销毁时关闭popubWindow
*/
@Override
protected
void
onDestroy() {
if
(
popubWindow
!=
null
){
popubWindow
.dismiss();
popubWindow
=
null
;
}
super
.onDestroy();
}
/*
* 7.在activity销毁时关闭popubWindow
*/
@Override
protected
void
onDestroy() {
if
(
popubWindow
!=
null
){
popubWindow
.dismiss();
popubWindow
=
null
;
}
super
.onDestroy();
}