可聚焦和可聚焦之间的区别?

我想知道它们之间的实际区别... ... 什么时候应该使用它们,应该如何使用它们,以及在什么情况下使用它们是有帮助的?

给出一些例子并详细解释。

68725 次浏览

It is explained in the Android Developers Blog: http://android-developers.blogspot.co.at/2008/12/touch-mode.html

The following quotes should make it clear:

By itself, the touch mode is something very easy to understand as it simply indicates whether the last user interaction was performed with the touch screen. For example, if you are using a G1 phone, selecting a widget with the trackball will take you out of touch mode;

...

In touch mode, there is no focus and no selection. Any selected item in a list of in a grid becomes unselected as soon as the user enters touch mode. Similarly, any focused widgets become unfocused when the user enters touch mode.

...

Now that you know focus doesn't exist in touch mode, I must explain that it's not entirely true. Focus can exist in touch mode but in a very special way we call focusable in touch mode. This special mode was created for widgets that receive text input, like EditText or, when filtering is enabled, ListView.

...

Focusable in touch mode is a property that you can set yourself either from code or XML. However, it should be used sparingly and only in very specific situations as it breaks consistency with Android normal behavior. A game is a good example of an application that can make good use of the focusable in touch mode property. MapView, if used in fullscreen as in Google Maps, is another good example of where you can use focusable in touch mode correctly.

Focused is a state for view and generally focus can be changed with trackball and dpad. Your view can have different background when state is focused.

Focusable in touch mode allows view to gain focus when user is touching the view, good example of this kind of component is EditText.

With Button or any clickable component pressed state is usually what you are interested in.

Give some example and explain them in detail

I'll give you my own experience:

I had a Google TV application which had an activity with a great deal of ImageButtons.

I wanted the ImageButtons to be selectable.

So if a person clicks on them with mouse or remote controller, they become selected only (Highlighted in my case). Then if the user presses the selected ImageButton, the action triggers. This exact behaviour was achieved through enabling the focusableInTouchMode property through the XML layout.

All I had to do was to set an ordinary onClickListener for the ImageButtons and voila!

I haven't checked my application on handset but I guess it would deliver familiar result.

EDIT

When?

I've told you a use case I have tested: When you want your Button's onClickListener to trigger action on your second click, after you have first clicked and selected the Button.

I Used the first click to gain "focus" and display a Zoom-In scale Up animation on my button.

How?

Just set the button's property focusableInTouchMode to true in your XML layout file.

Users can interact with their devices by using hardware keys or buttons, or by touching the screen. Touching the screen puts the device into touch mode. The user can then interact with it by touching the on-screen virtual buttons, images, etc.

To check if the device is in touch mode, call the View class's isInTouchMode() method.