我在Android中尝试使用Mapbox,但它没有显示在Android片段
上我收到以下错误
10-29 11:34:25.300 17208-17208/? I/art: Late-enabling -Xcheck:jni
10-29 11:34:25.657 17208-17208/com.example I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
10-29 11:34:25.795 17208-17251/com.example I/mbgl: {Map}[Android]: Not activating as we are not ready
10-29 11:34:25.796 17208-17251/com.example I/mbgl: {Map}[Android]: Not deactivating as we are not ready
10-29 11:34:25.852 17208-17252/com.example D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-29 11:34:25.876 17208-17208/com.example D/Atlas: Validating map...
10-29 11:34:25.950 17208-17252/com.example I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016_msm8226_LA.BF.1.1.1_RB1__release_AU ()
10-29 11:34:25.950 17208-17252/com.example I/Adreno-EGL: OpenGL ES Shader Compiler Version: E031.25.03.00
10-29 11:34:25.950 17208-17252/com.example I/Adreno-EGL: Build Date: 02/11/15 Wed
10-29 11:34:25.950 17208-17252/com.example I/Adreno-EGL: Local Branch:
10-29 11:34:25.950 17208-17252/com.example I/Adreno-EGL: Remote Branch: quic/LA.BF.1.1.1_rb1.10
10-29 11:34:25.950 17208-17252/com.example I/Adreno-EGL: Local Patches: NONE
10-29 11:34:25.950 17208-17252/com.example I/Adreno-EGL: Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1_RB1.05.00.02.042.016 + 62ca4eb + acd831d + 9f8b442 + e027a02 + cba30ba + 53c303a + a649d79 + 23e16f8 + 5e97da7 + cbd2a44 + 33d072a + 7aacf06 + 72b33e7 + 28f6f60 + b4c13d8 + NOTHING
10-29 11:34:25.957 17208-17252/com.example I/OpenGLRenderer: Initialized EGL, version 1.4
10-29 11:34:25.985 17208-17252/com.example D/OpenGLRenderer: Enabling debug mode 0
10-29 11:34:26.071 17208-17208/com.example E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-29 11:34:26.071 17208-17208/com.example E/mbgl: {Main}[OpenGL]: eglCreateWindowSurface() returned error 12296
10-29 11:34:26.072 17208-17208/com.example A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 17208 (.materialdesign)
MainActivity.java
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {
private static String TAG = MainActivity.class.getSimpleName();
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
// display the first navigation drawer view on app launch
displayView(0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
if(id == R.id.action_search){
Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new MapBoxFragment();
title = getString(R.string.title_home);
break;
case 1:
fragment = new FriendsFragment();
title = getString(R.string.title_friends);
break;
case 2:
fragment = new MessagesFragment();
title = getString(R.string.title_messages);
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.commit();
// set the toolbar title
getSupportActionBar().setTitle(title);
}
}
}
fragment_map.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mapbox.mapboxsdk.views.MapView
android:id="@+id/altMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapbox:accessToken="sk.sdfsdf......."/>
</FrameLayout>
MapboxFragment.java
public class MapBoxFragment extends Fragment {
private MapView mapView = null;
View convertView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
convertView = inflater.inflate(R.layout.fragment_map, null);
mapView = (MapView) convertView.findViewById(R.id.altMapView);
mapView.setStyle(Style.MAPBOX_STREETS);
mapView.setCenterCoordinate(new LatLng(0, 0));
// Show user location (purposely not in follow mode)
mapView.setMyLocationEnabled(true);
return convertView;
}
}
在活动中使用相同的布局时,它正在工作。
答案 0 :(得分:13)
当我更新我的Mapbox SDK for android时,我遇到了这个问题。我在初始化mapView.onCreate(savedInstanceState)
后添加MapView
解决了这个问题。希望这会有所帮助。