2016-11-03 33 views
1

有一個EditText建立在Android的擴展工具欄我想在的Android這是正常的工具欄的高度2X,並在下半部的EditText創建工具欄。如何在底部

目前,我有XML代碼(注意android:layout_height="128dp"):

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:title="Messages" 
      android:titleTextColor="@color/windowBackground" 
      android:background="@color/buttonBackground" 
      android:layout_height="128dp"  
      android:layout_width="match_parent" 
      android:minHeight="?android:attr/actionBarSize" 
      android:gravity="bottom" /> 

     <fragment 
      android:id="@+id/no_activity_fragment" 
      class="com.ohmd.ohmd.ui.main.MainActivityListFragment" 
      android:name="com.ohmd.ohmd.ui.main.MainActivityListFragment" 
      android:layout_below="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent"/> 

</RelativeLayout> 

這是什麼樣子(沒有EditText還): enter image description here

我」,所以有幾個問題米停留在:

  • (一)我怎樣才能獲得「MESSA ges「在高度設置爲"?android:attr/actionBarSize"時對齊頂部的位置?

  • (b) aftter將標題向上移動,如何在下半部分添加EditText視圖?

這是我希望能acheive: enter image description here

回答

0

G與它配合:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:title="Messages" 
     android:titleTextColor="@color/windowBackground" 
     android:background="@color/buttonBackground" 
     android:layout_width="match_parent" 
     android:layout_height="?android:attr/actionBarSize" 
     android:gravity="center" /> 

    <RelativeLayout 
     android:orientation="vertical" 
     android:background="@color/buttonBackground" 
     android:layout_height="?android:attr/actionBarSize" 
     android:layout_below="@+id/toolbar" 
     android:id="@+id/card_view" 
     android:layout_width="match_parent" 
     android:gravity="center"> 

      <EditText 
       android:layout_margin="10dp" 
       android:id="@+id/tvSection" 
       android:background="@color/buttonBackgroundSelected" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:gravity="center"/> 

    </RelativeLayout> 
0

那麼,你可以嘗試改變工具欄重力

android:gravity="top" 

如果不工作,你可以擺脫的「標題」並將TextView添加到工具欄中,如下所示:

<android.support.v7.widget.Toolbar 
    android:layout_width="match_parent" 
    android:layout_height="128dp" 
    android:background="@color/buttonBackground" 
    android:gravity="top" 
    android:minHeight="?android:attr/actionBarSize" 
    android:titleTextColor="@color/windowBackground"/> 

    <TextView 
     android:id="@+id/button_save" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="top|left" 
     android:text="Messages" 
     android:textColor="@color/buttonBackground"/> 

</android.support.v7.widget.Toolbar>