Android ApiDemos示例解析(115):Views->Focus->1. Vertical
来源:互联网 发布:安安电子狗软件 编辑:程序博客网 时间:2024/03/29 17:18
Android UI系统一般可以根据用户输入(方向键或是Track ball)在不同的UI控件中移动“焦点(Focus)”。并可以根据UI的显示或隐藏知道更换当前带有Focus的控件。而View可以通过isFocusable 返回值来确定它是否可以接受Focus。View调用setFocus 来决定它是否愿意接受Foucs. 而在支持Touchable 模式下,使用对应的isFocusableInTouchMode 和setFocusableInTouchMode方法。
缺省的移动Foucs的算法是寻找指定方向最近的一个UI控件。可以通过nextFocusDown, nextFocusLeft, nextFocusRight, 和 nextFocusUp来修改Focus缺省移动算法。nextFocusDown, nextFocusLeft, nextFocusRight, 和 nextFocusUp明确指定了不同方向上移动Focus的下一个UI控件。
本例使用垂直方向排列UI控件:并把WebView的focusable 设为false,没有使用nextFocusDown 和 nextFocusUp ,因此会使用Android缺省移动Focus的算法。
<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_1_message”
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_1_placeholder” />
</LinearLayout>
本例使用四种UI控件:
- TextView 缺省情况无法接受Focus,如果需要接受Foucs,可以设置android:focusable=”true”.
- ListView 含三个列表项Ars Technica”, “Slashdot”, “GameKult”,可以接受Focus
- WebView 将其 android:focusable=”false”,理论上通过方向键移动Focus时会跳过此View,但好像对WebView不起作用,也不知道是不是Android的Bug。
- Button, 缺省可以接受Focus。
- Android ApiDemos示例解析(115):Views->Focus->1. Vertical
- Android ApiDemos示例解析(141):Views->Layouts->LinearLayout->1. Vertical
- Android ApiDemos示例解析(151):Views->Layouts->RelativeLayout->1. Vertical
- Android ApiDemos示例解析(116):Views->Focus->2. Horizontal
- Android ApiDemos示例解析(117):Views->Focus->3. Circular
- Android ApiDemos示例解析(118):Views->Focus->4. Internal Selection
- Android ApiDemos示例解析(142):Views->Layouts->LinearLayout->2. Vertical (Fill Screen)
- Android ApiDemos示例解析(143):Views->Layouts->LinearLayout->3. Vertical (Padded)
- Android ApiDemos示例解析(107):Views->Controls->1. Light Theme
- Android ApiDemos示例解析(110):Views->Data Widgets->1. Dialog
- Android ApiDemos示例解析(119):Views->Gallery->1. Photos
- Android ApiDemos示例解析(121):Views->Grid->1. Icon Grid
- Android ApiDemos示例解析(133):Views->Layouts->Baseline->1.Top
- Android ApiDemos示例解析(153):Views->Layouts->ScrollView->1.Short
- Android ApiDemos示例解析(168):Views->Lists->1. Array
- Android ApiDemos示例解析(182):Views->Progress Bar->1. Incremental
- Android ApiDemos示例解析(188):Views->ScrollBars->1.Basic
- Android ApiDemos示例解析(105):Views->Buttons
- POJ 1330 Nearest Common Ancestors(求LCA的三种方法)
- 关于NSMutableDictionary排序
- 1.java contents
- Object Oriented Programming
- Vaadin Web应用开发教程(15):UI组件-Button
- Android ApiDemos示例解析(115):Views->Focus->1. Vertical
- Android ApiDemos示例解析(116):Views->Focus->2. Horizontal
- Android ApiDemos示例解析(117):Views->Focus->3. Circular
- android 屏幕测试程序 测试R G B三色 和 全黑, 全白5种状态
- 代码大全学习-20-不常见的控制结构(Unusual Control Structures)
- ArcGIS 10.1 for Server 集群(RHEL)安装配置
- QStringList类常用方法
- ubuntu一些设置技巧
- 鼠标键