【发布时间】:2018-03-24 00:39:53
【问题描述】:
所以我目前正在制作这个应用程序,这是我正在使用/编码的 activity_maps.xml 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<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"
<FrameLayout xmlns:android="https://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:id="@+id/btnRestaurant"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Nearby Restaurants"
android:visibility="visible" />
<Button
android:id="@+id/btnHospital"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Nearby Hospitals"
android:visibility="visible" />
<Button
android:id="@+id/btnSchool"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Nearby Schools"
android:visibility="visible" />
</FrameLayout>
显示的错误是,每当我将鼠标悬停在 linearlayout 上方时,它都会显示:应定义 layout_height 属性,应定义 layout_width 属性,Element LinearLayout 没有必需的属性 layout_height,Element LinearLayout 没有必需的属性 layout_width,错误方向?没有指定方向,默认是水平的,但是这个布局有多个孩子,其中至少一个有 layout_width="match_parent"。然后这些是我将鼠标悬停在 FrameLayout 上方时的错误:应该定义 layout_height 属性,应该定义 layout_width 属性。这些是我将鼠标悬停在按钮标签上方时出现的错误:应该定义 layout_height 属性,应该定义 layout_width 属性。这些是我将鼠标悬停在 abdroid:id="@+id/btnwhatever", android:text="whatever", android:visibility="visible" 标签上方时出现的错误,它们都说:Unexpected namespace prefix "android" found for tag Button . 当我将应用程序的布局更改为:
<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="350dp"
android:layout_height="500dp"
<FrameLayout xmlns:android="https://schemas.android.com/apk/res/android"
android:layout_height="125dp"
android:layout_width="75dp">
<LinearLayout
xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_height="75dp"
android:layout_width="100dp"
android:orientation="vertical">
<Button
android:id="@+id/btnRestaurant"
android:layout_height="10dp"
android:layout_width="10dp"
android:text="Nearby Restaurants"
android:visibility="visible" />
<Button
android:id="@+id/btnHospital"
android:layout_height="10dp"
android:layout_width="10dp"
android:text="Nearby Hospitals"
android:visibility="visible" />
<Button
android:id="@+id/btnSchool"
android:layout_height="10dp"
android:layout_width="10dp"
android:text="Nearby Schools"
android:visibility="visible" />
</LinearLayout>
</FrameLayout>
但是,当我执行没有显示错误的布局然后打开它在 logcat 上显示的地图时:java.lang.RuntimeException: Binary XML file line #0: You must provide a layout_width attribute 请帮忙,谢谢。 附言我刚刚取出了片段中的 tools:context="" 标签进行发布
【问题讨论】:
-
亲爱的 Mike,我已将 /> 放在片段代码的末尾,当我运行应用程序时它会显示在 log cat 中:java.lang.RuntimeException: Binary XML file line #0 :您必须提供一个 layout_width 属性,然后应用程序就会崩溃,说:不幸的是,地图已停止工作。请帮忙,谢谢!
标签: android android-layout android-linearlayout android-framelayout