• android view源码(翻译头部4)


    Drawing

    Drawing is handled by walking the tree and recording the drawing commands of
    any View that needs to update.
    通过走树并记录需要更新的任何视图的绘图命令来处理绘图

    After this, the drawing commands of the entire tree are issued to screen, clipped to the newly damaged area.
    此后,将整个树的绘制命令发布到屏幕,剪切到新损坏的区域。

    The tree is largely recorded and drawn in order, with parents drawn 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 before calling back to its <code>onDraw()</code> method.
    The child
    drawing order can be overridden with {@link ViewGroup#setChildrenDrawingOrderEnabled(boolean) custom child drawing order}in a ViewGroup,
    and with {@link #setZ(float)} custom Z values} set on Views.

       如果为视图设置背景可绘制,则视图将在调用其<code> onDraw</ code>方法之前对其进行绘制。
       可以在ViewGroup中使用{@link ViewGroup#setChildrenDrawingOrderEnabled(boolean)自定义子绘图顺序}覆盖子绘图顺序,
       并在视图上设置了{@link #setZ(float)}自定义Z值}。

    To force a view to draw, call {@link #invalidate()}.
    要强制绘制视图,请调用{@link #invalidate()}。

    EventHandlingThreading 事件处理线程
    The basic cycle of a view is as follows:
    视图的基本周期如下:
    An event comes in and is dispatched to the appropriate view.
    一个事件进入并调度到适当的视图。
    The view handles the event and notifies any listeners.
    该视图处理事件并通知所有监听器。
    If in the course of processing the event, the view's bounds may need to be changed, the view will call {@link #requestLayout()}.
    如果在处理事件的过程中,可能需要更改视图的范围,则该视图将调用{@link #requestLayout()}。
    Similarly, if in the course of processing the event the view's appearance may need to be changed, the view will call {@link #invalidate()}.
    同样,如果在处理事件的过程中可能需要更改视图的外观,则视图将调用{@link #invalidate()}。
    If either {@link #requestLayout()} or {@link #invalidate()} were called,the framework will take care of measuring, laying out, and drawing the tree as appropriate.
    如果调用了{@link #requestLayout()}或{@link #invalidate()},则该框架将负责适当地测量,布置和绘制树

    Note: The entire view tree is single threaded. You must always be on the UI thread when calling any method on any view.
    注意:整个视图树是单线程的。 在任何视图上调用任何方法时,您必须始终在UI线程上。
    If you are doing work on other threads and want to update the state of a view from that thread, you should use a {@link Handler}.
    如果您正在其他线程上工作,并且想要从该线程更新视图状态,则应使用{@link Handler}。

    FocusHandling

    The framework will handle routine focus movement in response to user input.
    该框架将响应用户输入来处理常规焦点移动。
    This includes changing the focus as views are removed or hidden, or as new views become available.
    这包括在视图被删除或隐藏或新视图可用时更改焦点。
    Views indicate their willingness to take focus through the {@link #isFocusable} method.
    视图表明他们愿意通过{@link #isFocusable}方法关注焦点。
    To change whether a view can take focus, call {@link #setFocusable(boolean)}. 
    要更改视图是否可以聚焦,请调用{@link #setFocusable(boolean)}。
    When in touch mode (see notes below) views indicate whether they still would like focus via {@link #isFocusableInTouchMode}and can change this via {@link #setFocusableInTouchMode(boolean)}.
    在触摸模式下(请参见下面的注释),视图表明它们是否仍希望通过{@link #isFocusableInTouchMode}进行聚焦,并可以通过{@link #setFocusableInTouchMode(boolean)}进行更改。
    Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. 
    焦点移动基于一种算法,该算法在给定方向上找到最近的邻居。
    In rare cases, the default algorithm may not match the intended behavior of the developer.
    在极少数情况下,默认算法可能与开发人员的预期行为不匹配。
    In these situations, you can provide explicit overrides by using these XML attributes in the layout file:
    在这些情况下,可以通过使用布局文件中的以下XML属性来提供显式覆盖:
    * nextFocusDown
    * nextFocusLeft
    * nextFocusRight
    * nextFocusUp
    To get a particular view to take focus, call {@link #requestFocus()}.
    要获得特定视图的关注,请致电{@link #requestFocus()}。

    TouchMode

    When a user is navigating a user interface via directional keys such as a D-pad,
    当用户通过方向键(例如D-pad)浏览用户界面时,
    it is necessary to give focus to actionable items such as buttons so the user can see what will take input.
    必须将重点放在可操作的项目(例如按钮)上,以便用户可以看到输入内容。
    If the device has touch capabilities, however, and the user begins interacting with the interface by touching it, it is no longer necessary to always highlight,
    or give focus to, a particular view.

       但是,如果设备具有触摸功能,并且用户通过触摸它开始与该界面进行交互,则不再需要始终突出显示,
       或关注特定的视图。

    This motivates a mode for interaction named 'touch mode'.
    这激发了一种称为“触摸模式”的交互模式。

    For a touch capable device, once the user touches the screen, the device will enter touch mode.
    对于具有触摸功能的设备,一旦用户触摸屏幕,该设备将进入触摸模式。
    From this point onward, only views for which{@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets.
    从现在开始,只有{@link #isFocusableInTouchMode}为真的视图才是可聚焦的,例如文本编辑小部件。
    Other views that are touchable, like buttons, will not take focus when touched; they will only fire the on click listeners.
    其他可触摸的视图(例如按钮)在被触摸时将不会聚焦。 他们只会触发点击监听器。
    
    
    Any time a user hits a directional key, such as a D-pad direction, the view device will exit touch mode, and find a view to take focus,
    每当用户按下方向键(例如D-pad方向)时,视图设备都会退出触摸模式,并找到要聚焦的视图,

    so that the user may resume interacting with the user interface without touching the screen again.
    因此用户可以继续与用户界面进行交互,而无需再次触摸屏幕。
    The touch mode state is maintained across {@link android.app.Activity}s.  
    触摸模式状态在{@link android.app.Activity}中保持不变。
    Call{@link #isInTouchMode} to see whether the device is currently in touch mode.
    致电{@link #isInTouchMode}以查看设备当前是否处于触摸模式。

    Scrolling
    The framework provides basic support for views that wish to internally scroll their content. 
    该框架为希望内部滚动其内容的视图提供了基本支持。
    This includes keeping track of the X and Y scroll offset as well as mechanisms for drawing scrollbars.
    这包括跟踪X和Y滚动偏移以及绘制滚动条的机制。
    See{@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and{@link #awakenScrollBars()} for more details.
    有关更多详细信息,请参见{@link #scrollBy(int,int)},{@ link #scrollTo(int,int)}和{@link #awakenScrollBars()}。


          关注本人公众号获取更多干货.

     
     
     
     
     


     
     
     
  • 相关阅读:
    换上 SansForgetica-Regular 字体,增加记忆能力
    Windows和Linux查看端口占用
    安卓打开远程调试(免root)
    debian系统解决包依赖问题的神器aptitude
    C# WinForm 实现窗体淡入淡出
    [图文教程]VS2017搭建opencv & C++ 开发环境
    C# 调用Tesseract实现OCR
    数据库工具链接阿里云MySQL数据库
    【转载】如何选择MySQL存储引擎
    java Long、Integer 、Double、Boolean类型 不能直接比较
  • 原文地址:https://www.cnblogs.com/wangandroid/p/13425427.html
Copyright © 2020-2023  润新知