2014-11-06 32 views
0

如何在RelativeLayout中添加一個操作欄?我正在使用actionbarSherlock添加一個操作欄,但我無法弄清楚如何將它添加到線性佈局中。原因是我想在操作欄上方和下方添加一些元素。Android如何在線性佈局中添加ActionBar?

編輯:

使用this library我可以用另一種觀點認爲向上滑動從底部的面板。但問題在於操作欄保持在頂部。下面是代碼,以使2片在layout.xml

<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/sliding_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="bottom" 
     sothree:panelHeight="68dp" 
     sothree:shadowHeight="4dp"> 

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:id="@+id/relativeone"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:text="Main Content" 
      android:textSize="16sp" /> 
</RelativeLayout> 


<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:id="@+id/relativtwo"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center|top" 
      android:text="The Awesome Sliding Up Panel" 
      android:textSize="16sp" /> 

</RelativeLayout> 

    </com.sothree.slidinguppanel.SlidingUpPanelLayout> 

這是我試過,但沒有工作仍然

 <com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/sliding_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="bottom" 
      sothree:panelHeight="68dp" 
      sothree:shadowHeight="4dp"> 

    <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:id="@+id/relativeone"> 

//I tried to place the menu in here but its completely wrong 
    <menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> 
    <item android:id="@+id/action_settings" android:title="@string/action_settings" 
     android:orderInCategory="100" /> 
</menu> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:text="Main Content" 
       android:textSize="16sp" /> 
    </RelativeLayout> 


    <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:id="@+id/relativtwo"> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center|top" 
       android:text="The Awesome Sliding Up Panel" 
       android:textSize="16sp" /> 

    </RelativeLayout> 

     </com.sothree.slidinguppanel.SlidingUpPanelLayout> 
+0

操作欄應該是您應用中最頂層的元素。被說不,你不能,除非你創建自己的視圖 – tyczj 2014-11-06 15:09:55

回答

0

可以顯示什麼是你的工作嗎?這幾乎類似於Custom action bar in relative layout

+0

我想讓這個庫附加一個操作欄到其中一個視圖https://github.com/umano/AndroidSlidingUpPanel – 2014-11-06 15:43:07

+1

好的庫!我只能想,如果現在是,你可以創建多個視圖/佈局的層次結構來放置元素。如github示例中所述,您的主滑動面板佈局需要兩個子組件。[自定義組件](http:// developer。 android.com/guide/topics/ui/custom-components.html)。這可能也有幫助。 – Chetandalal 2014-11-06 15:57:40