材料
- 屎丢丢
- PopupWindow
- loopView
具体实现步骤
- 在对应module下build.gradle添加依赖:
compile 'com.weigan:loopView:0.1.2'
- 创建popupWindow
/**
* 获取PopupWindow
*/
public static PopupWindow getPopupWindow(Context context, View vie, int rId, boolean isBelowView) {
//选择含有上下文的构造器
PopupWindow popupWindow = new PopupWindow(context);
//popupWindow显示的view
Activity ac = (Activity) context;
View view = ac.getLayoutInflater().inflate(rId, null);
if (!isBelowView) {
popupWindow.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
popupWindow.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
}
// view.getBackground().setAlpha(140);//这是设置弹出窗口的透明度的
popupWindow.setContentView(view);
//设置在popupWindow外点击的时候隐藏
popupWindow.setOutsideTouchable(true);
//设置背景
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//可以获得焦点,Button才可以点击,点击空白消失
popupWindow.setFocusable(true);
//第一个参数必须是当前Activity上面的组件view
if (isBelowView)
popupWindow.showAsDropDown(vie, 0, 0);
else
popupWindow.showAtLocation(vie, Gravity.BOTTOM, 0, 0);
return popupWindow;
}
- 新建popupWindow显示布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:id="@+id/pop_back"
android:layo