当我第二次打开我的SupportMapFragment(Android maps v2)(调用setContentView)时,我收到以下错误:
01-28 16:27:21.374: E/AndroidRuntime(32743): FATAL EXCEPTION: main
01-28 16:27:21.374: E/AndroidRuntime(32743): android.view.InflateException: Binary XML file line #6: Error inflating class fragment
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.view.View.inflate(View.java:16119)
01-28 16:27:21.374: E/AndroidRuntime(32743): at mypackage.MyView.<init>(HitsView.java:26)
01-28 16:27:21.374: E/AndroidRuntime(32743): at mypackage.MenuListFragment.onItemClick(MenuListFragment.java:133)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
01-28 16:27:21.374: E/AndroidRuntime(32743): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
01-28 16:27:21.374: E/AndroidRuntime(32743): …Run Code Online (Sandbox Code Playgroud) 我MapFragment里面的视差效果AppBarLayout:
我想禁用滚动AppBarLayout,因为无法在地图上移动,因为地图上的触摸偶数总是作为滚动事件处理.我想AppBarLayout通过RecyclerView仅滚动来处理折叠,这是在屏幕的底部.
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="@color/white"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true">
<fragment
android:id="@+id/map"
android:name="com.androidmapsextensions.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="73dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<include
android:id="@+id/search_bar"
layout="@layout/layout_searchbar" />
</android.support.v7.widget.Toolbar>
<View
android:id="@+id/toolbar_shadow"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@id/search_bar"
android:layout_gravity="bottom"
android:background="@drawable/toolbar_dropshadow"
android:visibility="gone" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RecyclerView
android:id="@+id/farm_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Run Code Online (Sandbox Code Playgroud)
感谢您的答复.
android supportmapfragment android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout
我Google Map API v2在我的应用程序中使用它来显示地图.
我已按照所有步骤进行操作,以便在我的应用程序中启用Google Map.
public class PinLocationOnMapView extends FragmentActivity {
private double mLatitude = 0.0, mLongitude = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = SupportMapFragment.newInstance();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我使用此代码,它会显示我的地图,但如果我提供我的纬度/经度值,地图图块不会加载,我只看到白色图块.
以下是上述类的onCreate()中编写的代码:
if (getIntent().getExtras() != null) {
final Bundle bundle = getIntent().getBundleExtra("LOCATION");
mLatitude = bundle.getDouble("LATITUDE");
mLongitude = bundle.getDouble("LONGITUDE");
} else {
finish();
}
GoogleMapOptions options = new GoogleMapOptions();
LatLng latLng = new LatLng(mLatitude, mLongitude);
CameraPosition cameraPosition;// = new CameraPosition(latLng, 0, 0, 0); …Run Code Online (Sandbox Code Playgroud) android google-maps google-maps-markers google-maps-api-2 supportmapfragment
我知道使用嵌套片段存在问题.但我的应用程序设计为在片段上运行,如果我将使用地图的活动,我的投射功能将有错误.
我想请教您如何实现这一目标.我一直在网上搜索,但我找不到最佳解决方案.
我试过这段代码:
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) myFragmentActivity.getSupportFragmentManager().findFragmentById(R.id.map_con))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setMyLocationEnabled(true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于R.id.map_con是我片段中的一个片段,这会给我重复的错误.
所以我寻找一个解决方法,这次,R.id.map_con是一个框架布局,在运行时我创建了SupportMapFragment.
SupportMapFragment mSupportMapFragment = new SupportMapFragment();
myFragmentActivity.getSupportFragmentManager().beginTransaction()
.replace(R.id.map_con, mSupportMapFragment).commit();
Run Code Online (Sandbox Code Playgroud)
虽然每次关闭并打开片段时这不会给我重复.但我的错误是mSupportMapFragment.getMap总是为空.我不明白为什么它的null?
mMap = mSupportMapFragment.newInstance().getMap();
if (mMap != null){
Log.e("ReportFragment","mMap is …Run Code Online (Sandbox Code Playgroud) 使用2个简单的活动.第一个Activity只包含一个按钮来启动第二个包含地图的Activity:
主要活动:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void goToMap(View view){ //This is just the onClick method for the button
Intent intent=new Intent( this, BigMapTest.class);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
地图活动:
public class BigMapTest extends FragmentActivity {
SupportMapFragment mapFragment;
GoogleMap map;
@Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.travel_diary_big_map);
mapFragment=(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.big_map);
map=mapFragment.getMap();
}
Run Code Online (Sandbox Code Playgroud)
地图活动的XML布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/big_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
Run Code Online (Sandbox Code Playgroud)
现在当我运行这段代码时,按下按钮移动到带有地图的Activity,然后按回去进入第一个活动...然后重复这个过程,我可以看到每次堆的大小都在增加,直到达到这是限制,然后开始钳制.如果你用地图(即缩放)混乱一点,我可以在这一点上获得一个OOM异常.
01-25 16:10:13.931:D/dalvikvm(21578):GC_FOR_ALLOC释放1898K,7%空闲45859K/49187K,暂停204ms …
android google-maps-android-api-2 supportmapfragment android-maps-v2
我的应用中有3个片段的活动.当按下第一个按钮时,会在Activity中调用一个方法,该方法执行一些不相关的操作然后调用finish().
这会触发onPause()片段,它会执行更多不相关的内容然后调用super.onPause().
然后,应用程序加载它出现的旧Activity(逻辑上跟随视图堆栈),并onDestroyView()在Fragment上调用时突然崩溃并出现以下异常:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to destroy activity {be.niteowl.niteowl.debug/be.niteowl.niteowl.views.activities.VenueActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2793)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2811)
at android.app.ActivityThread.access$2100(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:972)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1327)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1338)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
at be.niteowl.niteowl.views.activities.TrackFragment.onDestroyView(TrackFragment.java:161)
at android.support.v4.app.Fragment.performDestroyView(Fragment.java:1665)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:980)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) …Run Code Online (Sandbox Code Playgroud) android ondestroy illegalstateexception android-fragments supportmapfragment
我正在尝试使用为Android提供的最新Map API 2.0.我正在使用支持库,因为我想支持Android 2.2.以下是我的代码:
主要活动类
public class MainActivity extends FragmentActivity {
public FragmentManager fManager ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fManager = getSupportFragmentManager();
Button showMapButton = (Button) findViewById(R.id.showMapButton);
showMapButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
loadMapFragment();
}
});
}
private void loadMapFragment() {
MapPageFragment plotterFragment = new MapPageFragment();
FragmentTransaction ft = fManager.beginTransaction();
ft.replace(R.id.allFragmentsFrameLayout, plotterFragment);
ft.addToBackStack(null);
ft.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
主活动布局文件
<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" …Run Code Online (Sandbox Code Playgroud) maps android google-maps-api-2 android-fragments supportmapfragment
我在Fragment中实现Google Map时遇到了麻烦.
这是我的片段类的一部分:
public class FragmentStoreFinderMap extends Fragment implements OnMapReadyCallback {
// Google Map
private GoogleMap googleMap;
private int i;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
googleMap = ((SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(
R.id.map)).getMapAsync(this);
Run Code Online (Sandbox Code Playgroud)
我在getMapAsync(this)中收到错误.我告诉不兼容的类型.
它说:
必需:com.google.android.gms.map.GoogleMap
发现:无效
顺便说一句,这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android google-maps android-fragments supportmapfragment android-studio
我在我的三个标签片段中添加了一个全屏地图片段.除了我在标签之间切换时遇到的问题,一切都很有效.
每次我从带有地图的片段切换到其他片段之一时,我会得到一个0.2秒的黑屏.对于使用地图片段滚动活动的问题,这似乎是一个类似的问题.
我已经尝试在其他人建议的地方添加透明视图以外的地图,但它没有帮助.
这是我的xml:
<FrameLayout 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=".ParkMapFragment">
<fragment
android:id="@+id/fullParkMap"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public class ParkMapFragment extends Fragment {
public ParkMapFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_map, container, false);
}
@Override
public void onStart(){
super.onStart();
getActivity().setTitle("Map");
}
@Override
public void onDestroyView() {
super.onDestroyView();
SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.fullParkMap);
if (mapFragment != null) {
getFragmentManager().beginTransaction().remove(mapFragment).commit();
} …Run Code Online (Sandbox Code Playgroud) java android google-maps android-fragments supportmapfragment
我正在尝试在 Kotlin 中编写我当前的应用程序,但我得到 null 无法转换为非 null 类型。我尝试了很多不同的东西,但我一直遇到同样的问题。不知道该怎么办。任何帮助,将不胜感激!
代码:
class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
private lateinit var mMap: GoogleMap
private lateinit var button: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
val mapFragment = supportFragmentManager
.findFragmentById(R.id.mapFragment) as SupportMapFragment
mapFragment.getMapAsync(this)
}
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap;
setUpMap();
}
fun setUpMap() {
val et = findViewById<EditText>(R.id.editText);
val et2 = findViewById<EditText>(R.id.editText2);
val lat = et.getText().toString().toDouble();
val lng = et2.getText().toString().toDouble();
//val ll = LatLng(lat, lng)
button = findViewById(R.id.button) as Button
button.setOnClickListener …Run Code Online (Sandbox Code Playgroud) android ×10
google-maps ×5
android-collapsingtoolbarlayout ×1
java ×1
kotlin ×1
maps ×1
ondestroy ×1