
R.layout.imageup_pop
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:padding="5dp" >
<ListView
android:id="@id/imgupPopLv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#eee3d9"
android:dividerHeight="1px" />
</LinearLayout>
public class DirPopupWindow extends PopupWindow{
private int mWidth;
private int mHeight;
private ListView mListView;
private List<FolderBean> mData;
private FolderBean preSelFolder;
public DirPopupWindow(Context context, List<FolderBean> data) {
super(context);
mData = data;
calWidthAndHeight(context);
initViews(context);
initListener();
}
private void calWidthAndHeight(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
mWidth = metrics.widthPixels;
mHeight = (int) (metrics.heightPixels*0.7);
}
private void initViews(Context context) {
View contentView = LayoutInflater.from(context).inflate(R.layout.imageup_pop,null);
setContentView(contentView);
setWidth(mWidth);
setHeight(mHeight);
setFocusable(true);
setTouchable(true);
setOutsideTouchable(true);
setBackgroundDrawable(new BitmapDrawable());
setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE){
dismiss();
return true;
}
return false;
}
});
mListView = (ListView) contentView.findViewById(R.id.imgupPopLv);
mListView.setAdapter(new DirAdapter(context,R.layout.imageup_pop_item,mData));
}
private void initListener() {
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (null != mLisetner) {
if (null != preSelFolder) {
preSelFolder.setSel(false);
}
FolderBean bean = (FolderBean) parent
.getItemAtPosition(position);
bean.setSel(true);
preSelFolder = bean;
mLisetner.onSelected(bean);
}
}
});
}
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
super.showAsDropDown(anchor, xoff, yoff);
}
private class DirAdapter extends CommonAdapter<FolderBean>{
public DirAdapter(Context context, int layoutId, List<FolderBean> datas) {
super(context, layoutId, datas);
}
@Override
protected void convert(ViewHolder holder, FolderBean item, int position) {
ImageView img = holder.getView(R.id.popIvYl);
img.setImageResource(R.mipmap.pictures_no);
ImageLoader.getInstance().loadImage(item.getFirstImgPath(), img);
holder.setText(R.id.popTvDirName, item.getDirName());
holder.setText(R.id.popTvDirImgCount, item.getImgCountStr());
img = holder.getView(R.id.popImgSel);
int visible = item.isSel() ? View.VISIBLE : View.GONE;
img.setVisibility(visible);
}
}
private onDirSelectedListener mLisetner;
public interface onDirSelectedListener {
public void onSelected(FolderBean folder);
}
public void setOnDirSelectedLisetner(onDirSelectedListener mLisetner) {
this.mLisetner = mLisetner;
}
}
<style name="popupwindow_anim">
<item name="android:windowEnterAnimation">@anim/slide_up</item>
<item name="android:windowExitAnimation">@anim/slide_down</item>
</style>
slide_down
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="100%" />
</set>
slide_up
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="200"
android:fromXDelta="0"
android:fromYDelta="100%"
android:toXDelta="0"
android:toYDelta="0" />
</set>
R.layout.imageup_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="@id/imgupGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@color/transparent"
android:horizontalSpacing="3dp"
android:listSelector="@color/transparent"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="3dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#a000"
android:clipChildren="true">
<TextView
android:id="@id/imgupTvDirName"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:drawableRight="@drawable/tree"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="所有文件"
android:textColor="@color/white"
android:textSize="16sp"/>
<TextView
android:id="@id/imgupTvDirCount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="center_vertical"
android:paddingRight="10dp"
android:textColor="@color/white"
android:textSize="16sp"/>
</RelativeLayout>
</RelativeLayout>
tvDirName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDirPopupWindow.setAnimationStyle(R.style.popupwindow_anim);
mDirPopupWindow.showAsDropDown(tvDirName, 0, 0);
lightSwitch(0.3f);
}
});
private void initDirPopupWindow() {
mDirPopupWindow = new DirPopupWindow(this, mFolderBeans);
mDirPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
lightSwitch(1.0f);
}
});
mDirPopupWindow.setOnDirSelectedLisetner(new DirPopupWindow.onDirSelectedListener() {
@Override
public void onSelected(FolderBean folder) {
gridViewDatas(folder);
data2View(folder);
mDirPopupWindow.dismiss();
}
});
}
/**
* 内容区域明暗度设置
*/
private void lightSwitch(float alpha) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = alpha;
getWindow().setAttributes(lp);
}