【问题标题】:android: what is the difference between focused, enabled, pressed, and selected states?android:聚焦、启用、按下和选择状态有什么区别?
【发布时间】:2011-12-19 01:22:26
【问题描述】:

我查看了http://developer.android.com/reference/android/view/View.html 以找出差异,但不能理解太多。我只是部分理解了“选择”状态。

有人可以用一些可靠的例子来解释这些差异吗?我希望我的问题不是很模糊。如果是的话,如果有人可以帮助我改进它会很棒,因为我不知道如何更清楚地问它。

提前谢谢你。

【问题讨论】:

    标签: android view


    【解决方案1】:

    已启用 -> 可以进行用户交互。

    已禁用 -> 无法进行用户交互。

    • 如果您将鼠标悬停在某个小部件上,它会聚焦
    • 如果您按下(半按)该小部件,它会被按下
    • 如果您在鼠标在同一位置时按下和按下,则它被选中

    【讨论】:

    • 感谢您的澄清!不过,我仍然不清楚聚焦:聚焦状态如何在触摸屏中工作?是不是像这样:当我在屏幕上移动手指时,无论我的手指在任何特定时刻在哪里,屏幕的那个部分都有焦点?
    • 但是对于触摸输入,你通常只需要关心选中的状态,对吧? @EnginYapici 我认为文本字段在等待输入时会聚焦。
    • 使用触摸输入,您需要处理按下和选定状态。如果 touch-down 发生在 widget 内部,而 touch up 发生在 widget 外部,则不会被认为是选中的。
    • 实际上聚焦也适用于触摸界面。如果您在屏幕上有多个重叠的半透明视图(例如片段),则所有桌面范例都适用。此外,新的 Android 设备具有接近传感器,即使没有鼠标,也可以使“悬停”再次变得有意义。 Pressed/selected enabled/disabled 过于简单化了。
    【解决方案2】:

    Focused - (Window, View) 是键盘事件的目的地(是的,有些 Android 具有物理键盘),有些具有“除臭球”,可生成左上右下箭头键盘快捷键。

    已激活 - 已激活的小部件(视图)。例如。在多选列表中,选定的视图被激活。我相信 API 11 中这个额外阶段的必要性是由于激活了包含复选框的多选。因此选择和检查状态需要分开。

    Selected - 仅适用于复选框和其他可选视图。

    View states 的完整列表是(左边是StateSet id,右边是flag):

        R.attr.state_window_focused,    VIEW_STATE_WINDOW_FOCUSED,
        R.attr.state_selected,          VIEW_STATE_SELECTED,
        R.attr.state_focused,           VIEW_STATE_FOCUSED,
        R.attr.state_enabled,           VIEW_STATE_ENABLED,
        R.attr.state_pressed,           VIEW_STATE_PRESSED,
        R.attr.state_activated,         VIEW_STATE_ACTIVATED,
        R.attr.state_accelerated,       VIEW_STATE_ACCELERATED,
        R.attr.state_hovered,           VIEW_STATE_HOVERED,
        R.attr.state_drag_can_accept,   VIEW_STATE_DRAG_CAN_ACCEPT,
        R.attr.state_drag_hovered,      VIEW_STATE_DRAG_HOVERED
    

    另见:

    /**
     * Changes the activated state of this view. A view can be activated or not.
     * Note that activation is not the same as selection.  Selection is
     * a transient property, representing the view (hierarchy) the user is
     * currently interacting with.  Activation is a longer-term state that the
     * user can move views in and out of.  For example, in a list view with
     * single or multiple selection enabled, the views in the current selection
     * set are activated.  (Um, yeah, we are deeply sorry about the terminology
     * here.)  The activated state is propagated down to children of the view it
     * is set on.
     *
     * @param activated true if the view must be activated, false otherwise
     */
    public void setActivated(boolean activated)
    
    
    
    /**
     * Dispatch a key event to the next view on the focus path. This path runs
     * from the top of the view tree down to the currently focused view. If this
     * view has focus, it will dispatch to itself. Otherwise it will dispatch
     * the next node down the focus path. This method also fires any key
     * listeners.
     *
     * @param event The key event to be dispatched.
     * @return True if the event was handled, false otherwise.
     */
    public boolean dispatchKeyEvent(KeyEvent event)
    

    【讨论】:

    • 嗯,是的,我们对这里的术语深表歉意。 ?
    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 2018-08-11
    • 1970-01-01
    • 2011-06-17
    相关资源
    最近更新 更多