2016-12-01 120 views
0

我有三個佈局,一個用於顯示主菜單,另一個用於子菜單,第三個用於顯示詳細信息菜單。我必須使用鍵盤箭頭按鈕在這些佈局之間導航。向下移動主菜單到子菜單,從子菜單移動到詳細菜單的作品, 但問題是當我在詳細信息菜單中我無法進入子菜單。我嘗試使用屬性android:nextFocusUp,但它不適合我。如何在不同的佈局之間切換焦點

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" > 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#1c1c1c" 
      android:layout_marginLeft="100dp" 
      android:layout_marginRight="100dp" 
      > 

      <LinearLayout 
      android:id="@+id/pagelogolayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:background="@drawable/logoborder"> 

     <ImageView 
      android:id="@+id/logoimage" 
      android:layout_width="170dp" 
      android:layout_height="90dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/listpagelogo" 
      android:layout_marginLeft="10dp" 
      android:layout_marginBottom="15dp" 
      /> 

    </LinearLayout> 


    <RelativeLayout 
     android:id="@+id/mainmenu" 
     android:layout_width="match_parent" 
     android:layout_height="90dp" 
     android:layout_below="@+id/pagelogolayout" 
     android:orientation="horizontal" 
     android:background="@drawable/main_menu_border" 
     android:nextFocusDown="@+id/submenu" 
     android:focusable="true"> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/submenu" 
     android:layout_width="match_parent" 
     android:layout_height="70dp" 
     android:layout_below="@+id/mainmenu" 
     android:orientation="horizontal" 
     android:background="@drawable/sub_menu_border" 
     android:nextFocusDown="@+id/container" > 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/container" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_below="@+id/submenu" 
     android:layout_marginTop="30dp" 
     android:layout_marginLeft="30dp" 
     android:nextFocusUp="@+id/submenu" 
     /> 

     </RelativeLayout> 
</RelativeLayout> 

回答

0
view.requestFocus(); 

記:你的佈局有太多的嵌套佈局,它將使應用程序的性能下降