简体   繁体   中英

How to Add a Toolbar on RelativeLayout Android

I want to add toolbar to the image editing, but it works incorrectly when I add it as in the code. How do I add the toolbar to RelativeLayout? Each RelativeLayout adds a toolbar and appears on individual pages. How do I add toolbar? With this version of the code does not work correctly. You can see the image error in the photos. In MainActivity, the toolbar is attached.

图像问题 影像问题

    <LinearLayout 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"
        android:background="@drawable/..."
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="....RoomsActivity"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/selectableItemBackground"
        android:clickable="true"
        android:focusable="true"
        android:orientation="vertical"
        android:paddingBottom="@dimen/row_padding_vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/row_padding_vertical">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical" />

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:textColor="@color/colorPrimary"
            android:textSize="16dp"
            android:textStyle="bold" />

       ....
...
    </RelativeLayout>

    </LinearLayout>

Yes , you can add toolbar in RelativeLayout but you have to add android:layout_below="@+id/toolbar"

<?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" >

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />     

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
          android:layout_below="@+id/toolbar" /> 

    </RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM