android--View 你应该记住的一些事

Android自定义View之(一)View绘制流程详解——向源码要答案 前言 View作为整个app的颜值担当,在Android体系中占有重要的地位。深入理解Android View的绘制流程,对正确使用View来构建赏心悦目的外观,以及用自定义View来设计理想中的酷炫效果等方面,有着极其重要的帮助作用,所以将View的绘制流程作为自定义View系列文章的第一篇。当然,View的绘制流程原理,在现实的工作中是成为高级工程师路上必须克服的障碍;在面试中... 阅读详情

[1].A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.


[2].All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files.


[3].Note: The Android framework is responsible for measuring, laying out and drawing views. You should not call methods that perform these actions on views yourself unless you are actually implementing a ViewGroup.


[4].View IDs need not be unique throughout the tree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching.


[5].The geometry of a view is that of a rectangle. A view has a location, expressed as a pair of left and top coordinates, and two dimensions, expressed as a width and a height. The unit for location and dimensions is the pixel.


[6].It is possible to retrieve the location of a view by invoking the methods getLeft() and getTop(). The former returns the left, or X, coordinate of the rectangle representing the view. The latter returns the top, or Y, coordinate of the rectangle representing the view. These methods both return the location of the view relative to its parent. For instance, when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of its direct parent.


[7].The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values. 

The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent (see Layout for more details.) The measured dimensions can be obtained by calling getMeasuredWidth() and getMeasuredHeight().

The second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height. The width and height can be obtained by calling getWidth()and getHeight().


[8].Layout is a two pass process: a measure pass and a layout pass. The measuring pass is implemented in measure(int, int) and is a top-down traversal of the view tree. Each view pushes dimension specifications down the tree during the recursion. At the end of the measure pass, every view has stored its measurements. The second pass happens inlayout(int, int, int, int) and is also top-down. During this pass each parent is responsible for positioning all of its children using the sizes computed in the measure pass.


[9].The measure pass uses two classes to communicate dimensions. 

The View.MeasureSpec class is used by views to tell their parents how they want to be measured and positioned. 

MeasureSpecs are used to push requirements down the tree from parent to child. A MeasureSpec can be in one of three modes:

  • UNSPECIFIED: This is used by a parent to determine the desired dimension of a child view. For example, a LinearLayout may call measure() on its child with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how tall the child view wants to be given a width of 240 pixels.
  • EXACTLY: This is used by the parent to impose an exact size on the child. The child must use this size, and guarantee that all of its descendants will fit within this size.
  • AT_MOST: This is used by the parent to impose a maximum size on the child. The child must gurantee that it and all of its descendants will fit within this size.

The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:

  • an exact number
  • MATCH_PARENT, which means the view wants to be as big as its parent (minus padding)
  • WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding).

To initiate a layout, call requestLayout(). This method is typically called by a view on itself when it believes that is can no longer fit within its current bounds.


[10].Drawing is handled by walking the tree and rendering each view that intersects the invalid region. Because the tree is traversed in-order, this means that parents will draw before (i.e., behind) their children, with siblings drawn in the order they appear in the tree. If you set a background drawable for a View, then the View will draw it for you before calling back to its onDraw() method.

To force a view to draw, call invalidate().

[11].The basic cycle of a view is as follows:

  1. An event comes in and is dispatched to the appropriate view. The view handles the event and notifies any listeners.
  2. If in the course of processing the event, the view's bounds may need to be changed, the view will call requestLayout().
  3. Similarly, if in the course of processing the event the view's appearance may need to be changed, the view will call invalidate().
  4. If either requestLayout() or invalidate() were called, the framework will take care of measuring, laying out, and drawing the tree as appropriate.

Note: The entire view tree is single threaded. You must always be on the UI thread when calling any method on any view. If you are doing work on other threads and want to update the state of a view from that thread, you should use a Handler.


[12].Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.

Android之实现记住密码功能 1、至少创建两个EditText、一个CheckBox和一个Button组件,具体代码如下: private EditText phone; private EditText password; private Button Login; private CheckBox remember; //用于获取EditText的内容 private String phoneNum; private St... 阅读详情

相关推荐

安卓基础知识之View篇(一):View 必须要知道的基础知识

安卓基础知识系列旨在简明扼要地提供面试或工作中常用的基础知识,让对安卓还不太熟悉的小伙伴更快地入门。同时自己在工作中,也没法完全记住所有的基础细节,写这样的系列文章,可以让自己形成一个更完备的知识体系,同时给自己日后留个知识参考。 开始的开始 View 是除了安卓四大组件以外用的最多的控件,我们需要利用 Android 内置的 View 控件(TextView、LinearLayout等)完成业务需求,有时甚至需要自定义控件来满足特殊的业务需求。View 还负责与用户的交互(点击、滑动、长按等操作),掌.

qq_40987010的博客 4057

Android View 的文档注释说明

frameworks/base/core/java/android/view/View.java This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for ...

snail201211的博客 590

android实现登陆注册记住密码功能

本人开始学习Android,并做了一个登陆注册记住密码的Demo,注册功能将数据放到数据库中,本人是新手,接下来的这些可能对第一次写Android程序的人员来说会有些帮助的。可能有的地方写的不是很好,请大家勿喷。 这个是进入Android的主页面  点击登陆之后 会提示登陆成功,正在获取用户数据。。。 如果你是记住密码的进入这个程序的时候会有用户名和密码的,如果不是记住密码 就程序默认的就

Android多媒体开发指南 8508

android View 总结

/** * * This is called to find out how big a view should be. The parent * supplies constraint information in the width and height parameters. * * * * The actual m

一步一步走 1035

安卓基础知识之View篇(二):View 事件分发机制备忘录

安卓基础知识系列旨在简明扼要地提供面试或工作中常用的基础知识,让对安卓还不太熟悉的小伙伴更快地入门。同时自己在工作中,也没法完全记住所有的基础细节,写这样的系列文章,可以让自己形成一个更完备的知识体系,同时给自己日后留个知识参考。 开始的开始 View 事件分发机制是我觉得非常有意思的内容,依稀记得我第一次看完时恍然大悟的感觉,不禁赞叹设计者优秀的开发思维,居然能想到这么有才的事件分发方法,我内心十分佩服。今天回过头来重温了一遍事件分发机制的内容,我依然觉得精彩,本篇内容就让我们来探究 View 的事件.

qq_40987010的博客 1896

安卓基础知识之View篇(三):源码分析 View 事件分发机制

安卓基础知识系列旨在简明扼要地提供面试或工作中常用的基础知识,让对安卓还不太熟悉的小伙伴更快地入门。同时自己在工作中,也没法完全记住所有的基础细节,写这样的系列文章,可以让自己形成一个更完备的知识体系,同时给自己日后留个知识参考。 开始的开始 本篇文章基于 Android 12.0 版本,会从源码角度来体会事件从顶层 ViewGroup 往下传递的过程,以及 View 是如何处理传递过来的事件的。 正文 还记得备忘录里记的结论吗,如果你还不是很了解 View 事件传递机制的原理,直接看备忘录的结论可能会.

qq_40987010的博客 1878

android:layout_width="match_parent" 里为什么总是提示match_parent的类型不匹配

/* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */ package com.friend

autumn20080101的专栏 2239

从仿真到打样:PMOS栅极泄放电路设计全流程复盘与三个踩坑点总结

本文详细复盘了PMOS栅极泄放电路从仿真到打样的全流程设计,重点总结了三个关键踩坑点:三极管BE结过压击穿、静态功耗超标和栅极振荡现象。通过优化缓启动电路、改进保护设计和布局调整,最终实现18ms开通时间、190μs关断时间和8μA静态功耗的工业级性能指标,为类似电源开关设计提供实用参考。

weixin_28693683的博客 371

Android studio登录界面之记住密码

上一篇博客讲到Android studio 创建登录界面,留下了记住密码的难题,这一篇博客就聊聊这个checkBox按钮如何完成记住密码。同时,我们会了解到文件存储的几个方式。

genijmni的博客 1万+

音视频入门:H264、H265概念总结

添加链接描述 什么是H.264与H.265 H.264与H.265都是视频压缩格式,由于视频本身的码流太大,所以需要经过压缩然后再通过网络进行传输。H.264是目前比较主流的压缩算法,像视频会议设备一般都采用这个编码格式。基础的H.264可以支持在1M带宽下传输720P30帧/秒的图像;H.264 HIGH PROFILE支持在512K带宽下传输720P30帧/秒的图像。 H.265是比较新的压缩算法,可以更一步提高压缩比,随着我们现在生活中出现的视频格式越来越大(比如现在基本都是1080P甚至4K的显示器

weixin_40673765的博客 8940

【仿真】Carla Python API实战:从零搭建自动驾驶测试环境

本文详细介绍了如何使用Carla Python API从零搭建自动驾驶测试环境。通过Carla仿真平台,开发者可以构建高度逼真的城市环境和车辆物理模型,利用Python API实现传感器配置、数据采集、场景构建及自动驾驶算法集成。文章还分享了实际项目中的调试技巧和性能优化经验,帮助读者快速掌握自动驾驶仿真测试的核心技术。

weixin_29050513的博客 219

Android自定义View

概述 Android开发进阶的必经之路 为什么要自定义View 自定义View的基本方法 自定义View的最基本的三个方法分别是: onMeasure()、onLayout()、onDraw(); View在Activity中显示出来,要经历测量、布局和绘制三个步骤,分别对应三个动作:measure、layout和draw。 测量:onMeasure()决定View的大小; 布局:onLayout()决定View在ViewGroup中的位置; 绘制:onDraw()决定绘制这个View。 自定义控

Rayman的博客 1万+

4.UE数字人工程运行逻辑及程序逻辑

UE数字人工程运行逻辑及程序逻辑

6091

Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)

SharedPreferences介绍: SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置参数,它是采用xml文件存放数据的,文件存放在"/data/data/shared_prefs"目录下。 SharedPreferences的用法: 由于SharedPreferences是一个接口,而且在这个接口里没有提供写入数据和读取数据的能力。但

liuyiming_的专栏 17万+

从零到一:IC Compiler II(ICC II)后端设计流程详解

本文详细解析了IC Compiler II(ICC II)后端设计流程,从环境准备到物理实现,再到布线优化与签核验证。通过实战案例和高效技巧,帮助工程师掌握ICC II工具链的应用,提升数字集成电路设计的效率和质量。

weixin_30879169的博客 347

【unity实战】Unity游戏开发:如何用ScriptableObject与序列化多态实现可复用的模块化效果系统?

本文介绍了两种实现卡牌游戏效果系统的模块化设计方案。方案一使用ScriptableObject创建独立的效果资产,通过组合实现不同效果,优点是数据可复用、可视化编辑,缺点是同类不同参数效果需创建大量SO文件。方案二利用SerializeReference特性直接嵌套效果实例,避免SO文件过多,但需要插件支持编辑器多态显示。两种方案都将效果与卡牌解耦,提高了代码复用性和扩展性,解决了硬编码带来的重复、维护困难和扩展不便等问题。开发者可根据项目需求选择合适方案,或结合两者优势构建更灵活的系统。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 437

android怎么实现记住密码功能,Android实现用户登录记住密码功能

一、打开之前完成的Case_login进行修改再编辑二、将注册按钮删除并在登录按钮前拖出一个checkBox,编辑代码如下:在layout_top.xml文件中进行编辑android:layout_width="match_parent"android:layout_height="wrap_content"android:padding="@dimen/activity_horizontal_m...

weixin_32952295的博客 1926

PX4实战(四):PX4 uorb模块详解

本节主要讲解PX4中的uorb消息,主要包括uorb的基本概念使用、PX4内重要的uorb消息、如何自定义uorb消息以及使用uorb消息的注意点等,其中讲解重要uorb消息是为了对PX4内重要数据结构有初步的了解,有助于后期算法理解。uORB(micro Object Request Broker)是PX4中用于模块间通信的轻量级发布-订阅(Publish/Subscribe)机制。模块之间可以通过uORB传递消息,无需直接调用对方函数;提高系统模块化与解耦性;

PX4-SLAM-PNC 1933

Android开发之登录界面——记住密码

简单的实现了用户登录中,记住密码和取消记住密码。记住密码即首次成功登录后,再次登录不需要输用户名和密码;取消该功能后,每次登录都要填写相关信息。 功能交代好了,具体代码如下        逻辑代码: /**   * @author 作者 cocoa  * @E-mail: 506966949@qq.com  * @version 创建时间:2014年12月8日 下午12:41:27

调上调下的女生 1649

YOLO26改进 - 注意力机制 | MLLAttention (Mamba-Like Linear Attention) 类Mamba线性注意力:动态感受野适配多尺度目标

本文介绍了Mamba-Like Linear Attention (MLLA)模型及其在yolo26中的集成。MLLA结合了Mamba和线性注意力Transformer的优点,线性注意力降低计算复杂度,Mamba有效建模序列。该模型将Mamba的遗忘门和块设计等关键元素与线性注意力结合,还可用位置编码替代遗忘门。我们将MLLA引入yolo26,在检测头的不同尺度特征图上应用。实验表明,改进后的yolo26在目标检测任务中表现良好,体现了MLLA在提升模型性能上的有效性。

魔改工程师的博客 1151

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Android中实现登陆界面的记住密码功能

Android中实现登陆界面的记住密码功能所需工具实现逻辑:实现代码功能完善 所需工具 一:复选框控件:CheckBox, 二:SharedPreferences用于存储数据,该工具的读取和写入较为简单,放在代码里的注释中解释 实现逻辑: 如果没弄懂逻辑,代码看起来还是有点小难度的 一:判断SharedPreferences中已存入的CheckBox的Boolean信息(没有读取到则默认条件为“否...

It_is_IT_的博客 4843

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Android实现记住密码功能

这篇文章主要为大家详细介绍了Android实现记住密码功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本文实例为大家分享了Android实现记住密码功能的具体代码,供大家参考,具体内容如下 LoginActivity.java package com.wangdeqiang.www.chatwithrobot.BroadcastBestPractice; import andro...

qq_31600649的博客 2090

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

android怎么实现记住密码功能,Android实现记住密码功能

本文实例为大家分享了Android实现记住密码功能的具体代码,供大家参考,具体内容如下LoginActivity.javapackage com.wangdeqiang.www.chatwithrobot.BroadcastBestPractice;import android.content.Intent;import android.content.SharedPreferences;impo...

weixin_29540599的博客 1068

android用SharedPreferences实现登录时记住密码功能

只要两个Activity,一个登录界面MainActivity,一个登录成功后跳转的界面SuccessActivity(这个

qq_29614465的博客 4266

android:登录界面记住密码

利用SharePreferences将已经登陆成功的账号密码进行数据存储。对SharePreference中的数据进行读取。

weixin_62190821的博客 3163

android 登陆时记住密码

android 登陆时记住密码

qyqingyan的专栏 1507
上一篇: android--Content Provider 你应该记住的一些事-1
下一篇: android--Touch Events 你应该记住的一些事
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值