工具栏是否能够在RelativeLayout中工作?

Dan*_*KCl 6 android android-toolbar

我是Android编程的新手.我想问一下Toolbar能不能工作RelativeLayout?到目前为止,我设法使用它们创建它们LinearLayout.想听听大家的一些指导.谢谢.

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

kun*_*l.c 15

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

但是你需要提到布局:下面的属性因为它会重叠.

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>
Run Code Online (Sandbox Code Playgroud)

  • 最好将工具栏添加到末尾(因此它会在顶部),例如,如果您制作视频播放器,您希望视频上的透明工具栏 (2认同)