在Android Lollipop的AppCompat工具栏中定位视图

时间:2015-03-15 10:23:28

标签: android toolbar android-toolbar

我正在尝试将RelativeLayout放在工具栏中,以便我可以在工具栏中轻松定位视图。此工具栏用于独立模式,有两个菜单项。 我在我的布局xml文件中有这个:

<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"
    tools:context=".MainActivity"
    android:background="#ffffff">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:elevation="3dp"
    android:background="#ff17182b">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#f76865"
        android:layout_gravity="center_horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title"
            android:textSize="17sp"
            android:textStyle="bold"
            android:textColor="#ffffff"
            android:layout_alignParentTop="true"
            android:layout_marginTop="10dp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FFD10202"
            android:elevation="3dp"
            android:text="Stopped"
            android:textColor="#ffffff"
            android:padding="2dp"
            android:layout_marginTop="50dp"/>
        </RelativeLayout>

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

http://i.imgur.com/XLZx7Ts.png是指向生成的用户界面的屏幕截图的链接

使用上面的布局,RelativeLayout位于左侧,右侧边框位于工具栏菜单项的左侧边框。就好像菜单项覆盖了从屏幕顶部到工具栏末尾的区域,并且不允许在该区域内放置元素

请,我需要知道我做错了什么或者是否有正确的方法在工具栏中定位视图

0 个答案:

没有答案