poupwindow的应用+自定义对话框+自定义窗体

poupwindow的应用+自定义对话框+自定义窗体
一.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
在这里插入图片描述
1.步骤流程:

步骤1.实例化PopupWindow对象
步骤2.设置自定义布局、宽度和高度
步骤3.指定位置显示: showAsDropDown() showAtLocation()

2代码:
(1)xml布局文件:activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity"
    android:orientation="vertical"
    >
    <RelativeLayout
        android:background="#393A3F"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        >
        <TextView
            android:gravity="center_vertical"
            android:textColor="#fff"
            android:textSize="30sp"
            android:text="微信"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
        <ImageView
            android:layout_alignParentRight="true"
            android:layout_marginRight="50dp"
            android:src="@drawable/search"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
        <ImageView
            android:id="@+id/add"
            android:layout_alignParentRight="true"
            android:src="@drawable/add"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
    </RelativeLayout>

   <ListView
       android:id="@+id/lv"
       android:layout_weight="8"
       android:layout_width="match_parent"
       android:layout_height="0dp"></ListView>

   <RadioGroup
       android:layout_weight="1"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:orientation="horizontal">
       <RadioButton
           android:textAlignment="c
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值