2013-08-31 123 views
3

我正在使用如圖所示的導航抽屜here: Android Example。目前,操作欄是靜態的,當抽屜打開/關閉時它不會移動(只是標題更改)。如何申請這個效果:操作欄和導航抽屜 - 帶活動/片段的滑動操作欄

Image

我想整個動作條與滑動片段移動。並且ActionBar上的名稱和按鈕保持原樣。請告訴我你需要查看哪些代碼。

另外,問題2:

當你使用DrawerLayout你在XML中的FrameLayout(用於content_frame)和ListView(其中添加您的導航設置...那個抽屜裏有,可以修改佈局,使您可以添加不只是ListView的,但其他瀏覽藏漢在頂部或底部的ListView的事情是這樣的:??

enter image description here

我要添加ImageView的(不是超鏈接,只是圖片)和其他TextViews (用於說明)不超鏈接。

+1

看一看[這裏](http://stackoverflow.com/q uestions/11234375/how-did-google-manage-to-do-this-slide-actionbar-in-android-application) –

+0

我會將其添加到我的代碼中。請在我上面的編輯中查看問題2。 – KickAss

+0

@KickAss:如果可能的話,可以自定義代碼'NavigationDrawer',這對其他人也是有幫助的。 –

回答

9

考慮使用SlidingMenu庫從GitHub。這是強大的靈活性,你也可以做任何事情。您可以通過只簡單地調用滑動動作條:

setSlidingActionBarEnabled(true); 

https://github.com/jfeinstein10/SlidingMenu

+1

哇,如果我知道這2天前,我不會花2天的時間嘗試使Android示例工作和定製它:( – KickAss

+0

下載此代碼後。此代碼包含錯誤。請解決它,我很沮喪。 – AnAndroid

+0

實際上需要abs庫,那是什麼?請解決,請 – AnAndroid

1

我認爲這是你在找什麼。這是您引用示例的示例源代碼中的代碼。

// ActionBarDrawerToggle ties together the the proper interactions 
    // between the sliding drawer and the action bar app icon 
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ 
    mDrawerLayout, /* DrawerLayout object */ 
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ 
    R.string.drawer_open, /* "open drawer" description for accessibility */ 
    R.string.drawer_close /* "close drawer" description for accessibility */ 
    ) { 
     public void onDrawerClosed(View view) { 
      getActionBar().setTitle(mTitle); 
      invalidateOptionsMenu(); // creates call to 
             // onPrepareOptionsMenu() 
     } 

     public void onDrawerOpened(View drawerView) { 
      getActionBar().setTitle(mDrawerTitle); 
      invalidateOptionsMenu(); // creates call to 
             // onPrepareOptionsMenu() 
     } 
    }; 
    mDrawerLayout.setDrawerListener(mDrawerToggle); 
+0

是的,我已經在我的代碼中有這個了。 – KickAss

2

第二點:當然可以。 NavigationDrawer不僅限於使用ListView。只需使用一個像LinearLayout這樣的ViewGroup作爲DrawerLayout的第二個子元素,然後放入任何你想要的視圖。 但請記住在你的LinearLayout的規範中加入這一行:

<LinearLayout 
    ... 
    android:layout_gravity="start" 
    ...> 

    <TextView..../> 
    <ImageView...../> 
<LinearLayout/> 
2

我認爲你可以使用這種佈局,以實現對抽屜列表視圖頂部的一些觀點..

<!-- The main content view --> 

<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
</FrameLayout> 
<!-- The navigation drawer --> 

<RelativeLayout 
    android:id="@+id/drawerLeft" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="start" 
    android:background="#191919" > 

    <EditText 
     android:id="@+id/edit_Search" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#FC3A3B" 
     android:hint=" Search" 
     android:padding="10dp" 
     android:textColor="#ffffff" 
     android:textColorHint="#ffffff" > 

     <requestFocus /> 
    </EditText> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/edit_Search" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="5dp" 
     android:layout_marginRight="20dp" 
     android:src="@drawable/icon_small_search" /> 

    <ListView 
     android:id="@+id/drawer_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/edit_Search" 
     android:background="#191919" 
     android:choiceMode="singleChoice" 
     android:divider="#000000" 
     android:dividerHeight="1dp" > 
    </ListView> 
</RelativeLayout>