有人可以解释后裔焦点=后裔吗?

编程入门 行业动态 更新时间:2024-10-23 09:25:22
本文介绍了有人可以解释后裔焦点=后裔吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我很难理解descendantFocusability.非常特别afterDescendants.

I'm having hard time understanding descendantFocusability. Very particulary afterDescendants.

有人可以告诉我一个什么时候有用的例子吗?

Could someone show me an example of when this would be useful?

推荐答案

定义ViewGroup及其后代之间的关系,以寻找View作为焦点.

Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.

必须是以下常量值之一.

Must be one of the following constant values.

+------------------------------------------------------------------------------------------+ | Constant Value Description | +------------------------------------------------------------------------------------------+ | afterDescendants 1 The ViewGroup will get focus only if | | none of its descendants want it. | +------------------------------------------------------------------------------------------+ | beforeDescendants 0 The ViewGroup will get focus before | | any of its descendants. | +------------------------------------------------------------------------------------------+ | blocksDescendants 2 The ViewGroup will block its descendants from | | receiving focus. | +------------------------------------------------------------------------------------------+

您可以检查完整的示例此处.

You can check the complete example here.

代码段是:

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ListView listView = getListView(); Log.d(TAG, "onItemSelected gave us " + view.toString()); Button b = (Button) view.findViewById(R.id.button); EditText et = (EditText) view.findViewById(R.id.editor); if (b != null || et != null) { // Use afterDescendants to keep ListView from getting focus listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); if(et!=null) et.requestFocus(); else if(b!=null) b.requestFocus(); } else { if (!listView.isFocused()) { // Use beforeDescendants so that previous selections don't re-take focus listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); listView.requestFocus(); } } }

按照上面的代码片段,afterDescendants用于防止listview获得焦点,因此EditText或Button都可以请求焦点.

As per the above snippet, afterDescendants is used to prevent listview from getting focus, so that either EditText or Button can request focus.

注意:上面提供的链接已断开.请参阅我的要点以获取代码

Note: The link provided above is broken. Please refer to my Gist for the code

更多推荐

有人可以解释后裔焦点=后裔吗?

本文发布于:2023-06-13 09:38:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/679060.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后裔   焦点

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!