popupwindow的item_popupwindow布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
android:paddingBottom="2dp">
<View
android:layout_width="match_parent"
android:layout_height="2.25dp"
android:layout_alignParentTop="true"
android:background="#000000" />
<TextView
android:id="@+id/redio_21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="待支付" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
<TextView
android:id="@+id/redio_22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="已支付" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
<TextView
android:id="@+id/redio_23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="已取消" />
<View
android:layout_width="match_parent"
android:layout_height="1dp" />
</LinearLayout>
直接在oncreate里复制就行
//弹框的布局
View contentView = View.inflate(TheorderActivity.this, R.layout.item_popupwindow, null);
final PopupWindow popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setTouchable(true);//窗体可以触摸
popupWindow.setFocusable(true);//让窗体获取焦点
popupWindow.setOutsideTouchable(true);//设置窗体外部可以触摸
popupWindow.setBackgroundDrawable(new BitmapDrawable());//设置背景
TextView daizhifu = (TextView) contentView.findViewById(R.id.redio_21);
TextView yizhifu = (TextView) contentView.findViewById(R.id.redio_22);
TextView yiquxiao = (TextView) contentView.findViewById(R.id.redio_23);
//框的点击事件
daizhifu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewpager.setCurrentItem(0);
}
});
yizhifu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewpager.setCurrentItem(1);
}
});
yiquxiao.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewpager.setCurrentItem(2);
}
});
//图片的点击事件
popwindow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.showAsDropDown(popwindow);
}
});