Android-自定义PopupWindow

/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:padding=“8dp”

android:visibility=“gone” >

<ImageView

android:layout_width=“35dp”

android:layout_height=“35dp”

android:scaleType=“fitCenter”

android:src=“@drawable/ofm_collect_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:padding=“8dp”

android:visibility=“gone” >

<ImageView

android:layout_width=“35dp”

android:layout_height=“35dp”

android:scaleType=“fitCenter”

android:src=“@drawable/ofm_card_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”

android:visibility=“gone” />

<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_setting_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:padding=“8dp” >

<ImageView

android:layout_width=“35dp”

android:layout_height=“35dp”

android:scaleType=“fitCenter”

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

<Button

android:id=“@+id/btn_cancel”

android:layout_width=“wrap_content”

android:layout_height=“fill_parent”

android:layout_marginLeft=“10dp”

android:background=“@null”

android:gravity=“center”

android:text=“退出登录”

android:textColor=“@color/white”

android:textSize=“15sp” />

以上分别是主页面和两个popupWindow布局

下面自定义两个PopupWindow,自己封装自己想要的PopuoWindow,这里只是给出示例

/14_CustomPopupWindow/src/com/wwj/popupwindow/AddPopWindow.java

package com.wwj.popupwindow;

import android.app.Activity;

import android.content.Context;

import android.graphics.drawable.ColorDrawable;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup.LayoutParams;

import android.widget.LinearLayout;

import android.widget.PopupWindow;

/**

  • 自定义popupWindow

  • @author wwj

*/

public class AddPopWindow extends PopupWindow {

private View conentView;

public AddPopWindow(final Activity context) {

LayoutInflater inflater = (LayoutInflater) context

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

conentView = inflater.inflate(R.layout.add_popup_dialog, null);

int h = context.getWindowManager().getDefaultDisplay().getHeight();

int w = context.getWindowManager().getDefaultDisplay().getWidth();

// 设置SelectPicPopupWindow的View

this.setContentView(conentView);

// 设置SelectPicPopupWindow弹出窗体的宽

this.setWidth(w / 2 + 50);

// 设置SelectPicPopupWindow弹出窗体的高

this.setHeight(LayoutParams.WRAP_CONTENT);

// 设置SelectPicPopupWindow弹出窗体可点击

this.setFocusable(true);

this.setOutsideTouchable(true);

// 刷新状态

this.update();

// 实例化一个ColorDrawable颜色为半透明

ColorDrawable dw = new ColorDrawable(0000000000);

// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作

this.setBackgroundDrawable(dw);

// mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);

// 设置SelectPicPopupWindow弹出窗体动画效果

this.setAnimationStyle(R.style.AnimationPreview);

LinearLayout addTaskLayout = (LinearLayout) conentView

.findViewById(R.id.add_task_layout);

LinearLayout teamMemberLayout = (LinearLayout) conentView

.findViewById(R.id.team_member_layout);

addTaskLayout.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

AddPopWindow.this.dismiss();

}

});

teamMemberLayout.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

AddPopWindow.this.dismiss();

}

});

}

/**

  • 显示popupWindow

  • @param parent

*/

public void showPopupWindow(View parent) {

if (!this.isShowing()) {

// 以下拉方式显示popupwindow

this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);

} else {

this.dismiss();

}

}

}

/14_CustomPopupWindow/src/com/wwj/popupwindow/MorePopWindow.java

package com.wwj.popupwindow;

import android.app.Activity;

import android.content.Context;

import android.graphics.drawable.ColorDrawable;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup.LayoutParams;

import android.widget.PopupWindow;

public class MorePopWindow extends PopupWindow {

private View conentView;

public MorePopWindow(final Activity context) {

LayoutInflater inflater = (LayoutInflater) context

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

conentView = inflater.inflate(R.layout.more_popup_dialog, null);

int h = context.getWindowManager().getDefaultDisplay().getHeight();

int w = context.getWindowManager().getDefaultDisplay().getWidth();

// 设置SelectPicPopupWindow的View

this.setContentView(conentView);

// 设置SelectPicPopupWindow弹出窗体的宽

this.setWidth(w / 2 + 50);

// 设置SelectPicPopupWindow弹出窗体的高

this.setHeight(LayoutParams.WRAP_CONTENT);

// 设置SelectPicPopupWindow弹出窗体可点击

this.setFocusable(true);

this.setOutsideTouchable(true);

// 刷新状态

this.update();

// 实例化一个ColorDrawable颜色为半透明

ColorDrawable dw = new ColorDrawable(0000000000);

// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作

this.setBackgroundDrawable(dw);

// mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);

// 设置SelectPicPopupWindow弹出窗体动画效果

this.setAnimationStyle(R.style.AnimationPreview);

}

public void showPopupWindow(View parent) {

if (!this.isShowing()) {

this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);

} else {

this.dismiss();

}

}

}

上面用到一个动画样式效果:

/14_CustomPopupWindow/res/values/styles.xml

用到两个动画资源

/14_CustomPopupWindow/res/anim/fade_in.xml

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

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

android:interpolator=“@android:anim/accelerate_decelerate_interpolator”

android:fromXScale=“0.001”

android:toXScale=“1.0”

android:fromYScale=“0.001”

android:toYScale=“1.0”

android:pivotX=“100%”

android:pivotY=“10%”

android:duration=“200” />

/14_CustomPopupWindow/res/anim/fade_out.xml

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

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

android:interpolator=“@android:anim/accelerate_decelerate_interpolator”

android:fromXScale=“1.0”

android:toXScale=“0.001”

android:fromYScale=“1.0”

android:toYScale=“0.001”

android:pivotX=“100%”

android:pivotY=“10%”

android:duration=“200” />

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

总结

这次面试问的还是还是有难度的,要求当场写代码并且运行,也是很考察面试者写代码
因为Android知识体系比较庞大和复杂的,涉及到计算机知识领域的方方面面。在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。

附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)

里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

img-it8qfC40-1713216089885)]

[外链图片转存中…(img-hfNpnhUG-1713216089886)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

总结

这次面试问的还是还是有难度的,要求当场写代码并且运行,也是很考察面试者写代码
因为Android知识体系比较庞大和复杂的,涉及到计算机知识领域的方方面面。在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。

附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
[外链图片转存中…(img-wQuVLb80-1713216089887)]
里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值