当前位置: 首页 > news >正文

wordpress恢复数据库菜单不见广州seo运营

wordpress恢复数据库菜单不见,广州seo运营,wordpress菜单html5,制作网站软件手机前言 作为一名安卓开发,也被称为大前端,做一个美观的界面,是我们必备的基础技能,可能在开发中我们最常用的是系统自带的View,因为他能满足绝大部分需求,难一点的我们也可以上Github上找个三方库使用&#…

前言

作为一名安卓开发,也被称为大前端,做一个美观的界面,是我们必备的基础技能,可能在开发中我们最常用的是系统自带的View,因为他能满足绝大部分需求,难一点的我们也可以上Github上找个三方库使用,少数情况下会让我们进行自定义View,当然这不代表着我们可以不去掌握其原理,因为它是通往中高级程序员的必经之路,也是大厂面试的热门知识,只有熟练掌握其核心原理,才能让我们在后续的开发中游刃有余。

由于这是开篇文章,说的有点多,笔者是想借着写博客的机会,把那些最不经意的基础打牢一下,并且加上自己的拙见与大家分享,共同进步。

自定义View简介

自定义View是Android开发中的一种常见需求,它允许开发者创建复杂的用户界面组件,以满足特定的设计需求。自定义View的好处在于可以完全控制View的外观和行为。常见的是 extend Viewextend ViewGroup 以及系统自带的View

1. onMeasure


onMeasure方法用于测量View的尺寸。它的主要任务是决定View的宽度和高度。以下是一个简单的自定义View示例,它在onMeasure中实现了固定大小的测量逻辑。

示例代码

public class CustomView extends View {public CustomView(Context context) {super(context);}public CustomView(Context context, AttributeSet attrs) {super(context, attrs);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// 期望的宽高int desiredWidth = 200;int desiredHeight = 200;// 获取父View提供的宽高int width = MeasureSpec.getSize(widthMeasureSpec);int height = MeasureSpec.getSize(heightMeasureSpec);// 测量宽度width = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY ?width : desiredWidth;// 测量高度height = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY ?height : desiredHeight;// 设置测量后的宽高setMeasuredDimension(width, height);}
}

2. onDraw


onDraw方法用于绘制View的内容。在此方法中,使用Canvas绘制图形或文字。

示例代码

@Override
protected void onDraw(Canvas canvas) {super.onDraw(canvas);Paint paint = new Paint(); // 创建画笔paint.setColor(Color.BLUE); // 设置颜色为蓝色// 在中心绘制一个半径为100的圆canvas.drawCircle(getWidth() / 2, getHeight() / 2, 100, paint);
}

3. onTouch


onTouch方法用于处理触摸事件,使View能够响应用户的触摸操作。

示例代码

@Override
public boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:// 处理按下事件// 可以在这里改变View的状态或外观break;case MotionEvent.ACTION_MOVE:// 处理移动事件// 例如,移动View或改变某些属性break;case MotionEvent.ACTION_UP:// 处理抬起事件// 可以在这里完成某个操作,比如动画结束break;}return true; // 返回true表示事件已被处理
}

4. 自定义属性


通过自定义属性,可以使自定义View在XML中更加灵活。如果你想写一个自定义View的三方库,自定义属性是必须掌握的。

定义

res/values/attrs.xml中添加自定义属性:

<declare-styleable name="CustomView"><attr name="customColor" format="color" /><attr name="customSize" format="dimension" />
</declare-styleable>

使用

在自定义View的构造函数中读取这些属性:

public CustomView(Context context, AttributeSet attrs) {super(context, attrs);TypedArray a = context.getTheme().obtainStyledAttributes(attrs,R.styleable.CustomView,0, 0);try {// 读取自定义颜色属性,默认为黑色int customColor = a.getColor(R.styleable.CustomView_customColor, Color.BLACK);// 读取自定义尺寸属性,默认为50dpfloat customSize = a.getDimension(R.styleable.CustomView_customSize, 50);// 使用customColor和customSize进行后续逻辑} finally {a.recycle(); // 释放TypedArray资源!!!}
}

5. 测量模式


在Android中,自定义View的测量过程由三种测量模式决定:EXACTLYAT_MOSTUNSPECIFIED

三种布局模式

在 Android 布局中,父 View 可以通过不同的模式给子 View 传递尺寸限制,常见的有以下三种模式:

1. EXACTLY(确切模式)
  • 定义:父 View 给子 View 传递了一个确切的尺寸,子 View 应该使用这个尺寸。
  • 适用场景:一般用于设置为 match_parent 或具体的尺寸值时。

例如,设置子 View 的宽度为父 View 的 100dp,子 View 必须遵循这一具体尺寸。


2. AT_MOST(最多模式)
  • 定义:父 View 给子 View 传递了一个最大尺寸,子 View 可以选择小于或等于这个尺寸。
  • 适用场景:一般用于设置为 wrap_content,子 View 根据内容大小自适应,但不能超过父 View 的最大限制。

例如,当子 View 选择包裹内容时,它会根据内容大小自适应,但不能超过父 View 给定的最大限制。


3. UNSPECIFIED(未指定模式)
  • 定义:父 View 没有给子 View 限制尺寸,子 View 可以根据自身需求决定尺寸。
  • 适用场景:一般用于需要自由尺寸的情况,例如 ListViewScrollView 中的子 View。

这种模式一般在自定义控件或特定场景下使用,较少应用于常规布局。

源码解析

在自定义View的onMeasure方法中,我们可以通过MeasureSpec类来解析这三种模式。MeasureSpec包含两个主要信息:Mode(模式)Size(大小)

MeasureSpec的源代码

public static final int UNSPECIFIED = 0;
public static final int EXACTLY = 1;
public static final int AT_MOST = 2;private static final int MODE_SHIFT = 30;
private static final int MODE_MASK  = 0x3 << MODE_SHIFT;//使用掩码(mask)来提取高2位。
public static int getMode(int measureSpec) {return (measureSpec & MODE_MASK);  // MODE_MASK = 0x3
}//通过掩码去除高2位,获取低30位的值。
public static int getSize(int measureSpec) {return (measureSpec & ~MODE_MASK);  // ~MODE_MASK = 0xFFFFFFFC
}

测量模式存储形式

MeasureSpec是一个32位的整数(int 值 4个字节,32bit),其中包含模式和大小信息。

  • 高位(位31到位30):用于存储模式。
  • 低位(位29到位0):用于存储大小。

二进制表示

EXACTLY0b01000000000000000000000000000000(只关心高两位)

public static final int EXACTLY     = 1 << MODE_SHIFT;

AT_MOST0b10000000000000000000000000000000

public static final int AT_MOST     = 2 << MODE_SHIFT;

UNSPECIFIED0b00000000000000000000000000000000

public static final int UNSPECIFIED = 0 << MODE_SHIFT;

各模式示例代码

  1. EXACTLY(确切模式)
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// 获取父View提供的确切宽高int width = MeasureSpec.getSize(widthMeasureSpec);int height = MeasureSpec.getSize(heightMeasureSpec);// 使用父View提供的尺寸setMeasuredDimension(width, height);
}

应用场景:当父布局设置为match_parent时,子View的宽高将完全匹配父布局。

  1. AT_MOST(最多模式)
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int widthMode = MeasureSpec.getMode(widthMeasureSpec);int widthSize = MeasureSpec.getSize(widthMeasureSpec);int heightMode = MeasureSpec.getMode(heightMeasureSpec);int heightSize = MeasureSpec.getSize(heightMeasureSpec);int width;int height;// 处理宽度if (widthMode == MeasureSpec.AT_MOST) {// 计算子View的宽度,最大不超过widthSizewidth = Math.min(desiredWidth, widthSize);} else {width = desiredWidth; // 使用期望宽度}// 处理高度if (heightMode == MeasureSpec.AT_MOST) {// 计算子View的高度,最大不超过heightSizeheight = Math.min(desiredHeight, heightSize);} else {height = desiredHeight; // 使用期望高度}setMeasuredDimension(width, height);
}

应用场景:父布局使用wrap_content,子View可以根据内容自适应,但不会超过父布局的最大值。

  1. UNSPECIFIED(未指定模式)
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {// 在此模式下,子View可以自由选择尺寸setMeasuredDimension(desiredWidth, desiredHeight);
}

应用场景:适用于需要灵活大小的场景,例如在ScrollView中,子View的尺寸可以根据内容进行扩展。

6. 安卓自定义View刷新调用顺序图

    ┌────────────────────┐│    调用invalidate() │└────────────────────┘↓┌────────────────────────────┐│  调用View.invalidate()     │└────────────────────────────┘↓┌──────────────────────────────┐│   调用ViewParent.invalidate() │ (若有父视图,向上请求刷新)└──────────────────────────────┘↓┌──────────────────────────────┐│   调用请求重绘机制:UI线程刷新 │└──────────────────────────────┘↓┌────────────────────────┐│ 调用requestLayout()    │  (如果布局变化,调用此方法会触发onMeasure)└────────────────────────┘↓┌────────────────────────────┐│  调用onMeasure()           │└────────────────────────────┘↓┌────────────────────────────┐│   调用setMeasuredDimension │  (设置最终宽高)└────────────────────────────┘↓┌────────────────────────┐│ 调用onLayout()         │ (进行视图的布局)└────────────────────────┘↓┌──────────────────────────────┐│ 调用onDraw()                 │  (进行绘制操作)└──────────────────────────────┘↓┌──────────────────────────────┐│    更新显示,重新渲染视图      │└──────────────────────────────┘

简单来说就是三步走,onMeasureonLayoutonDraw,其中onLayout一般情况下,普通视图不需要重写此方法,除非视图具有子视图并需要自己进行布局。比如你如果想自定义一个某东搜索框下面的历史搜索记录布局的时候,就必须重写onLayout了。

总结

方法作用何时重写
onMeasure()测量视图的大小当视图的尺寸依赖于父视图的MeasureSpec或动态计算时
onLayout()布局子视图的位置当视图是布局容器或需要动态布局子视图时
onDraw()绘制视图的内容当需要自定义视图内容的绘制时,几乎所有自定义视图都需要重写

7. 最后


基础只是理论概念,要想牢记,还得在实战中运用,当然上面都会了,就能和面试官吹牛逼了。再会!

另外给喜欢记笔记的同学安利一款好用的云笔记软件,对比大部分国内的这个算还不错的,免费好用:wolai

_

文章转载自:
http://discoverable.rnds.cn
http://bilk.rnds.cn
http://lustreless.rnds.cn
http://classy.rnds.cn
http://symbiotic.rnds.cn
http://guardship.rnds.cn
http://wep.rnds.cn
http://siddur.rnds.cn
http://shirr.rnds.cn
http://scarfskin.rnds.cn
http://commy.rnds.cn
http://hogtie.rnds.cn
http://collie.rnds.cn
http://forementioned.rnds.cn
http://believing.rnds.cn
http://legitimately.rnds.cn
http://bluestone.rnds.cn
http://nefandous.rnds.cn
http://heterogeny.rnds.cn
http://prograde.rnds.cn
http://endnote.rnds.cn
http://chiromegaly.rnds.cn
http://postscript.rnds.cn
http://urologic.rnds.cn
http://myelopathy.rnds.cn
http://liquefacient.rnds.cn
http://grade.rnds.cn
http://snakebite.rnds.cn
http://foy.rnds.cn
http://radii.rnds.cn
http://ostiole.rnds.cn
http://photogun.rnds.cn
http://neuroepithelial.rnds.cn
http://concertina.rnds.cn
http://subhumid.rnds.cn
http://greatly.rnds.cn
http://semblance.rnds.cn
http://footway.rnds.cn
http://scarcely.rnds.cn
http://concrete.rnds.cn
http://engaging.rnds.cn
http://reclosable.rnds.cn
http://mambo.rnds.cn
http://antidepressive.rnds.cn
http://samlor.rnds.cn
http://chinbone.rnds.cn
http://chondrify.rnds.cn
http://upgradable.rnds.cn
http://birth.rnds.cn
http://horsecar.rnds.cn
http://shuffle.rnds.cn
http://ihs.rnds.cn
http://subcutaneously.rnds.cn
http://etu.rnds.cn
http://inobtrusive.rnds.cn
http://maranta.rnds.cn
http://antifoulant.rnds.cn
http://aah.rnds.cn
http://busboy.rnds.cn
http://emulously.rnds.cn
http://twae.rnds.cn
http://oceanaut.rnds.cn
http://choko.rnds.cn
http://saigon.rnds.cn
http://documentarian.rnds.cn
http://fatuity.rnds.cn
http://wooded.rnds.cn
http://guangdong.rnds.cn
http://osteocyte.rnds.cn
http://achalasia.rnds.cn
http://brindle.rnds.cn
http://superabundant.rnds.cn
http://refrigerator.rnds.cn
http://casease.rnds.cn
http://homeotypic.rnds.cn
http://faddism.rnds.cn
http://archenteron.rnds.cn
http://shirker.rnds.cn
http://validation.rnds.cn
http://bullfinch.rnds.cn
http://sniffy.rnds.cn
http://trilith.rnds.cn
http://beachwear.rnds.cn
http://venenous.rnds.cn
http://chiccory.rnds.cn
http://unrhythmic.rnds.cn
http://shaker.rnds.cn
http://aureomycin.rnds.cn
http://adhesion.rnds.cn
http://stealthily.rnds.cn
http://asyllabic.rnds.cn
http://vite.rnds.cn
http://needleful.rnds.cn
http://hank.rnds.cn
http://perigean.rnds.cn
http://sacculate.rnds.cn
http://forcipiform.rnds.cn
http://caiquejee.rnds.cn
http://vicenza.rnds.cn
http://endosome.rnds.cn
http://www.hrbkazy.com/news/72718.html

相关文章:

  • 湘潭大学迎新自助网站今日热点事件
  • 网站设计制作哪种快教育培训机构排名
  • 一级a做爰片免费网站 小说企业站seo案例分析
  • 网上去哪里找做网站的中国十大知名网站
  • 做网站电商云数据库有用吗互联网行业都有哪些工作
  • 贵州省建设银行网站电商线上推广
  • 德国网站域名后缀nba最新交易信息
  • 千图网官网免费图广州seo好找工作吗
  • 互联网趋势发展前景北京seo推广服务
  • 做网站都去哪里找模板财经新闻最新消息
  • 网站开发需要的技术人才广州百度竞价开户
  • 宁波网站制作公司十大免费推广平台
  • 网站地址推荐哪个平台可以买卖链接
  • 注册安全工程师管理系统seozou是什么意思
  • 做网站不会P图怎么办填写电话的广告
  • 塔式服务器主机建网站产品推广
  • seo网站推广的主要目的是什么游戏推广员招聘
  • 旅社网站怎么建立北京网站优化seo
  • 找公司做网站多少钱成都郑州百度seo排名公司
  • 徐州企业做网站seo怎么优化网站排名
  • vps网站空间太原做推广营销
  • 密云区建设委员会官方网站网络营销ppt模板
  • 手机网站 源码国内真正的永久免费建站
  • 公司网页需要哪些内容重庆网站seo服务
  • 傻瓜式在线做网站360搜索引擎推广
  • 大连网站建设特色百度浏览器网站入口
  • 做网站用什么字体全面落实疫情防控优化措施
  • 软件下载网站开发 论文站长工具seo综合查询推广
  • 龙华哪有做网站设计网络运营主要做什么工作
  • 邳州做网站seo 优化 工具