- 新建一个PopupWindwos的基本类
public class MoreCompanyPopupWindows extends PopupWindow {
private Context context;
private View parent;
private int yStart;
List<CompanyInfo> mDatas;
EditText et_company_code;
//构造函数接收传来的坐标以及数据
public MoreCompanyPopupWindows(Context context, View parent, int yStart, List<CompanyInfo> mDatas, EditText editText) {
this.context = context;
this.parent = parent;
this.yStart = yStart;
this.mDatas = mDatas;
this.et_company_code = editText;
initView();
}
private void initView() {
View view = View.inflate(context, R.layout.activity_login_item_more, null);
Resources resources = context.getResources();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
//设置弹出view的高度
setHeight(displayMetrics.heightPixels*7/8);
setBackgroundDrawable(new BitmapDrawable());
setFocusable(true);
//设置弹出收回的view动画,此处设置的为滑入滑出
setAnimationStyle(R.style.anim_pop_bottomber);
setOutsideTouchable(true);
setContentView(view);
showAtLocation(parent, Gravity.BOTTOM, 0, DensityUtil.dip2px(context, yStart));
update();
ImageView img_close = view.findViewById(R.id.close);
img_close.setOnClickListener(new CloseOnClickListener());
RecyclerView mRecyclerView = view.findViewById(R.id.data_company_more);
//データバインディング
LoginMoreAdapter loginMoreAdapter = new LoginMoreAdapter(context, mDatas, et_company_code,this);
mRecyclerView.setAdapter(loginMoreAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
linearLayoutManager.setAutoMeasureEnabled(true);
mRecyclerView.setLayoutManager(linearLayoutManager);
//行ごとにロゴを表示する
mRecyclerView.setLayoutManager(new GridLayoutManager(context, 4));
}
/**
* 終了
*/
private class CloseOnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
dismiss();
}
}
}
- 滑入滑出动画
<style name="anim_pop_bottomber">
<item name="android:windowEnterAnimation">@anim/anim_enter</item>
<item name="android:windowExitAnimation">@anim/anim_exit</item>
</style>
- anim_enter 滑入动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromYDelta="100%p"
android:toYDelta="0"/>
</set>
- anim_exit滑出动画
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromYDelta="0"
android:toYDelta="100%p"/>
</set>
- 调用
productsMoreCompanyPopupWindows = new MoreCompanyPopupWindows(this, see_more, 0, mDatas, et_company_code);