Android ApiDemos example resolution (115): Views-& gt; Focus-& gt; 1. Ver

Source: Internet
Author: User

Generally, the Android UI system can move "Focus" in different UI controls based on user input (direction keys or Track balls )". You can change the current control with Focus based on the display or hide of the UI. View can determine whether it can accept the Focus through the returned value of isFocusable. View calls setFocus to determine whether it is willing to accept Foucs. In Touchable mode, View uses the corresponding isFocusableInTouchMode and setFocusableInTouchMode methods.

The default Algorithm for moving foucos is to find a UI control closest to a specified direction. You can use nextFocusDown, nextFocusLeft, nextFocusRight, and nextFocusUp to modify the default moving algorithm of Focus. NextFocusDown, nextFocusLeft, nextFocusRight, and nextFocusUp specify the next UI control for moving the Focus in different directions.

In this example, the UI control is arranged vertically: The focusable of WebView is set to false, and nextFocusDown and nextFocusUp are not used. Therefore, the Android default Focus moving algorithm is used.

<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_height = "wrap_content"
Android: layout_width = "match_parent"
Android: orientation = "vertical">

<TextView android: id = "@ + id/txtStatus"
Android: text = "@ string/focus_shadowmessage"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"/>

<ListView android: id = "@ + id/rssListView"
Android: background = "#7700CC00 ″
Android: layout_height = "wrap_content"
Android: layout_width = "match_parent"/>

<WebView android: id = "@ + id/rssWebView"
Android: background = "#77CC0000 ″
Android: layout_height = "50dip"
Android: layout_width = "match_parent"
Android: focusable = "false"/>

<Button android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"
Android: text = "@ string/focus_?placeholder"/>

</LinearLayout>

In this example, four UI controls are used:

TextView cannot accept Focus by default. If you need to accept Foucs, you can set android: focusable = "true ".
ListView contains three list items: Ars Technica, Slashdot, and GameKult, which can be set to Focus.
WebView sets its android: focusable = "false". Theoretically, this View will be skipped when the direction key is used to move the Focus, but it does not seem to work for WebView and does not know whether it is a Android Bug.
Button. By default, Focus is acceptable.


Author: mapdigit

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.