工具栏能够在RelativeLayout中工作吗?

工具栏能够在RelativeLayout中工作吗?

问题描述:

我是Android编程新手。我想问一下Toolbar能工作在RelativeLayout吗?到目前为止,我设法使用LinearLayout来创建它们。希望听到一些指导形式,你所有。谢谢。工具栏能够在RelativeLayout中工作吗?

现在的问题是:如何防止内容重叠在Toolbar内容之上?

+0

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

+0

它不适用于Android的旧版本,除非布局:在工具栏下方的视图中指定了下方,它会重叠。 – saraf 2016-02-10 10:47:39

是的,我们可以在相对布局中添加工具栏。

但是你需要提及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