gpt4 book ai didi

java - 膨胀类 fragment 时出错

转载 作者:行者123 更新时间:2023-12-02 04:55:03 25 4
gpt4 key购买 nike

我正在尝试在 fragment 内膨胀 map fragment ,如下代码所示:

public class HomeFragment extends Fragment {

public HomeFragment(){}
public GoogleMap mMap;
private LocalizeDB db;
private FragmentActivity myContext;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.activity_maps, container, false);

return rootView;
}

@Override
public void onResume() {
super.onResume();
setUpMapIfNeeded();
}
}

activity_maps.xml代码

<fragment 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"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

我收到以下错误:二进制 XML 文件第 #1 行:膨胀类 fragment 时出错

如果我不是膨胀activity_maps.xml,而是膨胀fragment_home.xml,它就可以工作。但我需要膨胀 map fragment ...(activity_maps.xml)

fragment_home.xml代码:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/txtLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16dp"
android:text="Home View"/>

<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtLabel"
android:src="@drawable/ic_home"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>

</RelativeLayout>

最佳答案

改变

android:name="com.google.android.gms.maps.SupportMapFragment"

class="com.google.android.gms.maps.SupportMapFragment

"

关于java - 膨胀类 fragment 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28859910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com