android - 无法解释或解决 XML 中的片段元素的问题
问题描述
到目前为止,该应用程序只有一种布局,activity_main.xml
.
该应用程序在连接 USB 的开发人员 Android 手机上运行但几乎立即退出。
我尝试对应用程序进行调试和故障排除,但结果始终相同:应用程序不断退出。
最后,我尝试编辑应用程序中唯一的布局,activity_main.xml
. 我开始添加、删除和交换元素。
我发现fragment
删除元素后应用程序运行良好,我不知道该问题的解释或解决方案。
这是activity_main.xml
下面的。fragment
我提到 的元素具有supportMap
id
属性。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<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">
<FrameLayout
android:id="@+id/driverStatusLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimary"
android:orientation="horizontal">
<TextView
android:id="@+id/totalOnlineDrivers"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:gravity="center"
android:text="@string/total_online_drivers"
android:textColor="@color/common_google_signin_btn_text_dark"
android:textSize="22sp" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/driverStatusSwitch"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:layout_marginRight="15dp"
android:checked="false" />
</FrameLayout>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/supportMap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/driverStatusLayout"
tools:context="spartons.com.frisbeeGo.fragments.MapFragment" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
这是MainActivity.java
:
package com.example.testbasna;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends AppCompatActivity {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
解决方案
推荐阅读
- java - Spring 以合格 bean 为条件
- php - 如何修复脚本缓存:清除 symfony 4 中返回的错误代码 255
- excel - 从 OneDrive 同步的 Excel 文件显示在线文件路径,而不是本地文件
- c++ - delete[] 在 C++ 中用 new 分配的特定数组块
- wordpress - pre_get_posts 不限制每页的帖子
- docker - 使用 docker stack 进行 Docker 镜像版本控制
- azure - Azure API 管理中的拆分成本
- google-classroom - 主题创建后如何安排?
- html - Firefox中虚线边框的CSS问题
- python - 返回 networkx 中每个节点的后续节点数