popupwindow是我们在开发中常用的组件,本文将主要介绍实现popupwindow的方法:
实现效果:
实现步骤:
1、设置button,对button设置一个点击事件,即点击时跳出popupwindow
<Button
android:id="@+id/btn_button"
android:textAllCaps="false"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="popup" />
Button btn=findViewById(R.id.btn_button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
2、设置popupWindow的布局
此处可以用recyclerView或者listView来实现,此处写法只是为了展示效果
此处的View的首字母一定要大写!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_good"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="20dp"
android:paddingBottom="20dp"
android:text="好" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background