1、xml资源文件
1.主布局activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="打开泡泡窗口" />
</RelativeLayout>
2.popupwindow.xml
<?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:background="@android:color/white"
android:padding="20dp"
android:orientation="vertical">
<RadioGroup
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:text="全部拦截"
android:id="@+id/rb_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:text="电话拦截"
android:id="@+id/rb_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:text="电话拦截"
android:id="@+id/rb_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
<LinearLayout
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="修改"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="取消"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
3.样式文件:style.xml
<style name="popWindow_animation">
<item name="android:windowEnterAnimation">@anim/popupwindow_enter</item>
<item name="android:windowExitAnimation">@anim/popupwindow_exit</item>
</style>
4.泡泡窗体进入动画:popupwindow_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromYDelta="100%p"
android:toYDelta="0" />
<alpha
android:duration="500"
android:fromAlpha="0.5"
android:toAlpha="1.0" />
</set>
5.泡泡窗体进入动画:popupwindow_exit.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.5" />
<translate
android:fromYDelta="0"
android:toYDelta="100%p"
android:duration="500" />
</set
2、java代码
1.初始化泡泡窗体设置
private void initPopupWindow() {
View popView = getLayoutInflater().inflate(R.layout.popupwindow, null)
popupWindow = new PopupWindow(popView,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
popupWindow.setFocusable(true)
popupWindow.setBackgroundDrawable(new BitmapDrawable())
popupWindow.setOutsideTouchable(true)
}
2.显示泡泡窗体
private void showPoPupWindow(View parent) {
popupWindow.setAnimationStyle(R.style.popWindow_animation);
popupWindow.showAtLocation(parent, Gravity.BOTTOM,0,0);
}