viewPagerを使用してマップをアクティビティに表示したいが、まだXMLファイルのレンダリングに問題がある。viewPagerでアクティビティのGoogleマップを追加
フラグメントタグを使用すると、レイアウトファイルに異なる レイアウトを実行時に動的に含めることができます。レイアウト編集時に、 になる特定のレイアウトは不明です。レイアウトを編集中に をプレビューするレイアウトを選択できます。 -
(レイアウトを選択してください...)
はまた、Logcat
でエラーを作成して、このセッションでは、タグについて
add_masjid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentStart="true"
android:text="@string/xyz"
android:textColor="#FFFFFF"
android:textSize="20sp"
/>
<Button
android:id="@+id/generalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="@drawable/rect1"
android:onClick="geoLocate"
android:text="@string/abc"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/generalId"
android:layout_alignBottom="@+id/generalId"
android:layout_toEndOf="@+id/textView1"
android:layout_toStartOf="@+id/generalId"
android:ems="10"
android:inputType="text"
android:labelFor="@+id/editText1" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/generalId" />
</RelativeLayout>
に警告しません。
FATAL EXCEPTION: main
Process: com.example.saroosh.masjidnow, PID: 9220
android.view.InflateException: Binary XML file line #44: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.example.saroosh.masjidnow.Tabs.AddMasjid.onCreateView(AddMasjid.java:26)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
AddMasjid.java
package com.example.saroosh.masjidnow.Tabs;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.saroosh.masjidnow.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
public class AddMasjid extends Fragment {
MapView gMapView;
GoogleMap gMap = null;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.add_masjid,container,false);
// gMapView = (MapView) v.findViewById(R.id.map);
// gMapView.getMapAsync(this);
// gMapView.onCreate(savedInstanceState);
// gMapView.onResume(); // needed to get the map to display immediately
// try {
// MapsInitializer.initialize(getActivity().getApplicationContext());
// } catch (Exception e) {
// e.printStackTrace();
// }
return v;
}
// @Override
// public void onMapReady(GoogleMap map) {
// gMap = map;
// gMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
// gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
// LatLng(49.39,-124.83), 20));
// }
// @Override
// public void onResume() {
// super.onResume();
// gMapView.onResume();
// }
//
// @Override
// public void onPause() {
// super.onPause();
// gMapView.onPause();
// }
//
// @Override
// public void onDestroy() {
// super.onDestroy();
// gMapView.onDestroy();
// }
//
// @Override
// public void onLowMemory() {
// super.onLowMemory();
// gMapView.onLowMemory();
// }
}
この問題を解決する方法を教えてください。
[google-map-v2-fragment-rendering](http://stackoverflow.com/questions)に記載されているように、プレビューでフラグメントに含まれるものがわからないことが原因です。/23898992/android-studio-google-map-v2-fragment-rendering)、このエラーは無視できます。 – KLajdPaja
しかし、まだLogcatでエラーが発生しています。 –
@KLajdPaja私の場合は満足できる答えではありません。 –