Android-自定义PopupWindow,flutter开发实战详解pdf

本文详细介绍了如何在Android中自定义PopupWindow,包括布局设计和自定义类的实现,同时还提及了相关Flutter开发的知识,提供了一套完整的Android移动开发学习资料,涵盖高级UI、性能优化、架构师课程等多个方面。
摘要由CSDN通过智能技术生成

/14_CustomPopupWindow/res/layout/more_popup_dialog.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:gravity=“center_horizontal”

android:orientation=“vertical” >

<LinearLayout

android:id=“@+id/pop_layout”

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:layout_alignParentRight=“true”

android:layout_alignParentTop=“true”

android:background=“@drawable/abc_ab_bottom_solid_dark_holo”

android:gravity=“center_horizontal”

android:orientation=“vertical” >

<LinearLayout

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”

android:padding=“8dp” >

<ImageView

android:layout_width=“50dp”

android:layout_height=“50dp”

android:src=“@drawable/defalt_head” />

<LinearLayout

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:gravity=“left|center_horizontal”

android:orientation=“vertical”

android:padding=“5dp” >

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:text=“wwj”

android:textColor=“@color/white”

android:textSize=“15sp” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:text=“whatswwj”

android:textColor=“@color/green”

android:textSize=“15sp” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“0.2dp”

android:background=“@color/black” />

<LinearLayout

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”

android:padding=“8dp” >

<ImageView

android:layout_width=“35dp”

android:layout_height=“35dp”

android:scaleType=“fitCenter”

android:src=“@drawable/ofm_photo_icon” />

<TextView

android:layout_width=“wrap_content”

android:layout_height=“fill_parent”

android:layout_marginLeft=“10dp”

android:gravity=“center”

android:text=“我的相册”

android:textColor=“@color/white”

android:textSize=“15sp” />

<TextView

android:layout_width=“fill_parent”

android:layout_height=“0.2dp”

android:background=“@color/black” />

<LinearLayout

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”

android:p

  • 23
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当您需要更高级的弹窗样式和交互时,可以使用 PopupWindow 来创建自定义布局的弹窗。下面是使用 PopupWindow 创建自定义布局的步骤: 1. 创建自定义布局文件:首先,创建一个 XML 文件来定义您的自定义布局。例如,您可以创建一个名为 `custom_popup.xml` 的文件,并在其中定义您希望显示的布局。 2. 实例化 PopupWindow:在您的 Activity 或 Fragment 中,实例化 PopupWindow 对象。 ```java LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View customView = inflater.inflate(R.layout.custom_popup, null); PopupWindow popupWindow = new PopupWindow(customView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); ``` 3. 设置 PopupWindow 属性:根据需要,设置 PopupWindow 的属性,例如背景、动画效果、焦点等。 ```java popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setFocusable(true); // 设置动画效果 popupWindow.setAnimationStyle(R.style.PopupAnimation); ``` 4. 设置布局中的控件和事件:通过 `customView` 获取布局中的控件,并设置相应的事件监听器。 ```java Button button = customView.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 处理点击事件 } }); ``` 5. 显示弹窗:使用 `showAtLocation()` 或 `showAsDropDown()` 方法显示弹窗。`showAtLocation()` 方法可以显示在指定的位置,而 `showAsDropDown()` 方法则可以显示在某个视图的下方。 ```java View anchorView = findViewById(R.id.anchor_view); // 锚点视图 popupWindow.showAsDropDown(anchorView); // 或者使用 showAtLocation() 方法 ``` 这样,您就可以使用 PopupWindow 创建自定义布局的弹窗。希望对您有所帮助!如果有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值