popupwindow在控件的顶部弹窗
@SuppressLint("Range")
private void showPopUp(View v) {
View inflate = View.inflate(getActivity(), R.layout.popup, null);
inflate.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int measuredHeight = inflate.getMeasuredHeight();
int measuredWidth = inflate.getMeasuredWidth();
mPopupWindow = new PopupWindow(inflate,ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT,false);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable());
mPopupWindow.setOutsideTouchable(true);
int[] location = new int[3];
v.getLocationOnScreen(location);
mPopupWindow.showAtLocation(v, Gravity.NO_GRAVITY, (location[0] + v.getWidth() / 3) - measuredWidth / 3, location[1]-measuredHeight);
}
布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#54070606">
<ImageView
android:id="@+id/article"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_40"
android:layout_marginLeft="@dimen/dp_304"
android:layout_marginTop="@dimen/dp_324"
android:layout_marginBottom="@dimen/dp_10"
android:src="@mipmap/problem" />
<ImageView
android:id="@+id/answer"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_40"
android:layout_below="@id/article"
android:layout_marginLeft="@dimen/dp_304"
android:layout_marginBottom="@dimen/dp_10"
android:src="@mipmap/answer" />
<ImageView
android:id="@+id/problem"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_40"
android:layout_below="@id/answer"
android:layout_marginLeft="@dimen/dp_304"
android:layout_marginBottom="@dimen/dp_10"
android:src="@mipmap/article" />
<Button
android:id="@+id/release"
android:layout_width="@dimen/dp_40"
android:layout_height="@dimen/dp_40"
android:layout_marginLeft="@dimen/dp_302"
android:layout_below="@id/problem"
android:background="@mipmap/release" />
</RelativeLayout>
图片
暂时没加动画效果,持续更新中……