你嘗試過android視圖的nextFocusRight/Left/Up/Down屬性嗎?
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:nextFocusRight="@+id/button2" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:nextFocusRight="@id/button1" />
您可以在Java代碼中設置這些屬性。
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
Button button3 = (Button) findViewById(R.id.button3);
button3.setNextFocusRightId(R.id.button1);
在'onCreate'獲取所有需要的按鈕的視圖引用,並將它們存儲在一個數組中。然後你可以遍歷數組並改變焦點 – Panther 2014-12-19 09:02:10
@Panther我有更簡單的方法嗎?我記得c#有一個名爲'tabindex'的屬性可以控制按下'TAB'時的順序。 – roger 2014-12-19 09:18:29