PopupWindow弹出窗体

PopupWindow 显示方法

显示方法 显示位置
showAsDropDown(View anchor, int xoff, int yoff) 显示在anchor控件的下方
showAtLocation(View parent, int gravity, int x, int y) 显示在parent控件的某个位置

一.PopupWindow介绍

PopupWindow弹出窗体可以在任意位置弹出窗体,而对话框只能出现屏幕最中间。

二.如何自定义窗体

(1)构造方法:public PopupWindow (Context context):context上下文对象
(2)必须设置的3大要素:

 setContentView():设置自定义布局	
 setWidth():设置宽度	
 setHeight():设置高度

(3)显示窗体:

a.显示在某个指定控件的下方showAsDropDown(View anchor):showAsDropDown(View anchor, int xoff, int yoff);
//xoff和yoff都是偏移量
b.指定父视图,显示在父控件的某个位置(Gravity.TOP,Gravity.RIGHT等)       
 showAtLocation(View parent, int gravity, int x, int y);
 //gravity可以是Gravity.TOP、Gravity.BOTTOM、Gravity.LEFT、Gravity.RIGHT

三.实现微信QQ支付宝右上角加号弹出窗体

在这里插入图片描述

1.步骤流程:
      步骤1.实例化PopupWindow对象     
      步骤2.设置自定义布局、宽度和高度
      步骤3.指定位置显示:   	showAsDropDown()     showAtLocation()
2代码
       (1)xml布局文件:activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">
    <RelativeLayout
        android:id="@+id/Rl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:padding="10dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="微信"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:textSize="20sp"
            android:textColor="#FFFFFF"/>
        <ImageView
            android:id="@+id/Iv"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/add"
            android:layout_alignParentRight="true"/>
    </RelativeLayout>
    <ListView
        android:id="@+id/Lv"
        android:layout_below="@id/Rl"
        android:layout_above="@id/Rg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </ListView>
    <RadioGroup
        android:id="@+id/Rg"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#EEEEEE">
        <RadioButton
            android:id="@+id/Rb1"
            android:checked="true"
            android:layout_weight="1"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="消息"
            android:textColor="@drawable/text_color"
            android:drawableTop="@drawable/message"
            android:textSize="20sp"
            android:button="@null"/>
        <RadioButton
            android:id="@+id/Rb2"
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值