如何在googlemaps布局上创建工具栏

时间:2015-06-29 16:59:22

标签: android layout

我想知道如何创建如下图所示的工具栏。我想知道如何在googlemaps片段本身上创建一个工具栏,但不是在片段的顶部,我想知道它可以居中。我不想显示标签。我是新手设计android的布局,有人可以帮忙吗? enter image description here

 <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=".MapsActivity" >

<fragment
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />



 </RelativeLayout>

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.curtis.firstmap/com.example.curtis.firstmap.MapsActivity}: java.lang.RuntimeException: Failed to resolve attribute at index 6
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
        Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 6
        at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:603)
        at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6473)
        at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6641)
        at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1243)
        at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:1083)
        at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:82)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:808)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
        at android.app.Activity.setContentView(Activity.java:2145)
        at com.example.curtis.firstmap.MapsActivity.onCreate(MapsActivity.java:24)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:23
         at android.app.ActivityThread.access$800(ActivityThread.java:151)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)

2 个答案:

答案 0 :(得分:0)

<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=".MapsActivity" >

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/main_color"
            android:minHeight="?attr/actionBarSize"/>

    <fragment
        android:id="@+id/map"
        android:layout_below="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />



</RelativeLayout>

答案 1 :(得分:0)

你可以试试这个。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true"
    tools:context=".MapsActivity">

    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:id="@+id/view">

        <android.support.v7.widget.Toolbar android:id="@+id/****"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.design.widget.AppBarLayout>



    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="*****" />

</android.support.design.widget.CoordinatorLayout>