Android |将导航抽屉添加到默认地图活动
我一直在寻找这个星期的答案,所以请原谅,如果我看起来有点沮丧。这是因为我。Android |将导航抽屉添加到默认地图活动
提前,对不起,如果这个问题之前已被问过。我是Android新手(我主要做网络应用程序),对我来说这是一个全新的世界。所有帮助表示赞赏!
我想要做的是添加一个导航抽屉到mill maps活动的标准运行。我会如何去做这件事?我希望每个按钮都能够将地图重新映射到另一个地方。
虽然我们在这里,但我打算在地图上创建一个KML图层。如您所知,KML点内置了信息,因此当您点击/点击它们时,您可以看到信息。我想让KML点使用其内置信息打开导航抽屉。我很好用这个默认的Android点,但与KML东西赞赏。如果你想要一个参照系,认为像这样的JavaScript的例子,但与隐藏的大部分时间侧边栏:https://developers.google.com/maps/documentation/javascript/kml
MainActivity.java:
package us.tourismproject.jared.tourismprojectandroid;
import android.content.res.Resources;
import android.nfc.Tag;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MapStyleOptions;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
private static final String TAG = MainActivity.class.getSimpleName();
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
try {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
boolean success = googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this, R.raw.style_json));
if (!success) {
Log.e(TAG, "Style parsing failed.");
}
} catch (Resources.NotFoundException e) {
Log.e(TAG, "Can't find style. Error: ", e);
}
// Position the map's camera near Sydney, Australia.
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-34, 151)));
}
}
activity_main.xml中
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="us.tourismproject.jared.tourismprojectandroid.MainActivity" />
感谢您的任何帮助提前。现在好日子!
首先,您需要将Fragment
包装在另一个父级布局中,其中包括Navigation drawer
,然后在java中为drawer
设置事物。 参考this
来到交互部分,KML
只是一个符号,它拥有一些信息,你所能做的就是为每一个KML地理点,并把它绑的点击功能打开Navigation drawer
。
Check here添加标记到谷歌地图
我将如何着手创建所有KML点的点击功能?我对Java/Android的知识非常有限。尽管我有地图工作,所以对你很赞赏。 –
想通了!我使用OnMarkerClickListener创建一个onMarkerClick布尔值,它检查哪个标记被点击。然后它打开一个单独的片段。感谢所有帮助的人! –
很高兴我能帮忙:) –
如果你想抽屉式导航栏在你的地图活动比更新activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="us.tourismproject.jared.tourismprojectandroid.MainActivity" />
<android.support.design.widget.NavigationView android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Draw your view whatever you want to draw -->
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
它将创建您的导航抽屉一个答案通过提拉詹,你需要编写一些代码来处理导航抽屉。
你想要什么?您想在MainActivity中添加导航抽屉 –