本例横向显示UI控件,并使用了nextFocusRight 明确为Button 指定按右键时下一个获取焦点的UI控件为rightButton (跳过中间的Button),但是从右到左时还是按照缺省顺序。
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:orientation=”horizontal”>
<Button android:id=”@+id/leftButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”3dip”
android:text=”@string/focus_2_left”
android:nextFocusRight=”@+id/rightButton”/> <!– jump over middle! –>
<Button android:id=”@+id/centerButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”3dip”
android:text=”@string/focus_2_jump” />
<Button android:id=”@+id/rightButton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginRight=”3dip”
android:text=”@string/focus_2_right”/>
</LinearLayout>
本文介绍了一个Android UI布局示例,通过LinearLayout实现按钮横向排列,并利用nextFocusRight属性自定义焦点移动顺序,使得从左到右时,焦点可以跳过中间按钮直接移至最右侧按钮。

2万+

被折叠的 条评论
为什么被折叠?



