1.实现思路。
利用popwindow的showAsDropDown方法,结合自定义background样式。
2.java代码
PopupWindow searchConditionPopwindow = null;
View contentView = null;
public void showSearchConditionPopwindow(View parent){
if(contentView == null){
contentView = getLayoutInflater().inflate(R.layout.search_condition_popwindow,null);
}
if(searchConditionPopwindow == null){
searchConditionPopwindow = new PopupWindow(contentView,
parent.getLayoutParams().width, LinearLayout.LayoutParams.WRAP_CONTENT,true);
searchConditionPopwindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.search_condation_popwindow_style));
}
searchConditionPopwindow.showAsDropDown(parent);
}
3.popwindow背景样式
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="5dp"
>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners android:radius="6dp"></corners>
<solid android:color="#bbffffff"/>
</shape>
</item>
</layer-list>
注意,设置item 的 top = 5dp,目的是让popwindow不紧贴在附着view的下面。
4.效果实现