Android 4.2.2地图碎片问题
我有一个带有工具栏的地图和坐标布局中的自动完成搜索栏。在4.x以上的Android版本中,一切正常,但在Android 4.2.2中,只显示地图。工具栏和自动完成文本视图未显示 请帮助我理解为什么会发生这种情况 Xml:Android 4.2.2地图碎片问题,android,google-maps,android-coordinatorlayout,supportmapfragment,mapfragment,Android,Google Maps,Android Coordinatorlayout,Supportmapfragment,Mapfragment,我有一个带有工具栏的地图和坐标布局中的自动完成搜索栏。在4.x以上的Android版本中,一切正常,但在Android 4.2.2中,只显示地图。工具栏和自动完成文本视图未显示 请帮助我理解为什么会发生这种情况 Xml: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schema
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<include
android:id="@+id/toolbar"
layout="@layout/activity_self_assigned_toolbar" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:background="#FFFF"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="@+id/autocomplete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="0.5"
android:hint="Type in your Location">
</AutoCompleteTextView>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0"
android:id="@+id/custom_map_cross"
android:src="@drawable/icn_close"/>
<!--<Button-->
<!--android:id="@+id/search_button"-->
<!--android:layout_width="20dp"-->
<!--android:layout_weight="0.5"-->
<!--android:layout_height="40dp"-->
<!--android:layout_marginRight="5dp"-->
<!--android:layout_gravity="center"-->
<!--android:padding="5dp"-->
<!--android:background="@color/indigo_500"-->
<!--android:textColor="@android:color/white"-->
<!--android:text="Save" />-->
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
更大版本上相同代码的图像(代码工作正常):
检查一下这个
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:background="#FFFF"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="@+id/autocomplete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="0.5"
android:hint="Type in your Location">
</AutoCompleteTextView>
<ImageView
android:id="@+id/custom_map_cross"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0"
android:src="@drawable/pick_ticket_bg_large" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
您的MapFragment
与工具栏和自动完成搜索栏重叠,请将它们保持在MapFragment
上方
试试这个
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="@+id/toolbar"
layout="@layout/activity_self_assigned_toolbar" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:background="#FFFF"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="@+id/autocomplete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="0.5"
android:hint="Type in your Location">
</AutoCompleteTextView>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0"
android:id="@+id/custom_map_cross"
android:src="@drawable/icn_close"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
它的地图片段覆盖了你的工具栏,为你的地图片段设置了页边空白,然后你就可以看到工具栏了——问题出在你的XML文件上。请检查您的预览在不同的android版本在工作室你会得到很多。这样愚蠢的错误。谢谢你的帮助。另外,如果你投票支持这个问题,我将不胜感激。是的,这很有效。非常感谢。另外,如果您投票支持这个问题,我将不胜感激。
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
android:id="@+id/toolbar"
layout="@layout/activity_self_assigned_toolbar" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="60dp"
android:background="#FFFF"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="@+id/autocomplete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="0.5"
android:hint="Type in your Location">
</AutoCompleteTextView>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="0"
android:id="@+id/custom_map_cross"
android:src="@drawable/icn_close"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>