示例:
一、代码部分:
1.弹出框页面布局(layout/pop_mesure_layout.xml)
<!--LinearLayout不能设置背景颜色-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--@color/arrowViewColor设置背景透明度为0-->
<com.chy.tools.ArrowView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/arrowViewColor"
android:padding="20dp">
<ListView
android:id="@+id/measureListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"/>
</com.chy.tools.ArrowView>
</LinearLayout>
二、java代码:
/**
* 测量方法
* */
public void measureMapOperation(View v){
// 获取弹出框布局
View measureView = LayoutInflater.from(context).inflate(R.layout.pop_measure_layout, null);
// 创建数组,承接坐标值(x坐标值:location[0],y坐标值:location[1])
int[] location = new int[2];
// view相对于整个屏幕的左上角坐标
v.getLocationOnScreen(location);
// view相对于当前Activity的左上角坐标
//v.getLocationInWindow(location);
popWindow = new PopupWindow(measureView, 200, 220);
// 设置这句话,点击pop以外区域回dismiss
popWindow.setOutsideTouchable(true);
int offsetX = location[0] - popWindow.getWidth();
int offsetY = location[1] - popWindow.getHeight()/5;
popWindow.showAtLocation(v,Gravity.NO_GRAVITY,offsetX,offsetY);
// 测量数组
final List<String> measureList = Arrays.asList(new String[]{"测距","测面"});
measureAdapter = new MeasureAdapter(context,measureList);
ListView listView = measureView.findViewById(R.id.measureListView);
listView.setAdapter(measureAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,View view,int position,long id) {
resertOperation();//重置
String result = measureList.get(position);
if ("测距".equals(result)){
// 测距方法
measureDistance();
}
if ("测面".equals(result)){
// 测面方法
measureArea();
}
}
});
}