2014-11-24 57 views
3

我是Android編程新手。我想問一下Toolbar能工作在RelativeLayout嗎?到目前爲止,我設法使用LinearLayout來創建它們。希望聽到一些指導形式,你所有。謝謝。工具欄能夠在RelativeLayout中工作嗎?

現在的問題是:如何防止內容重疊在Toolbar內容之上?

+0

我看不出它不會工作。 – 2014-11-24 11:48:23

+0

它不適用於Android的舊版本,除非佈局:在工具欄下方的視圖中指定了下方,它會重疊。 – saraf 2016-02-10 10:47:39

回答

11

是的,我們可以在相對佈局中添加工具欄。

但是你需要提及layout:屬性,因爲它會重疊。

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     android:background="#ffbb00"> 


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

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/toolbar" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="49dp" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
+0

將嘗試...謝謝! – DanKCl 2014-11-28 16:59:55