java–Android:如何在不使用地图活动的情况下实现com.google.android.gms.maps.MapView

java–Android:如何在不使用地图活动的情况下实现com.google.android.gms.maps.MapView,第1张

概述我试图在线性布局中实现MapView,这个布局不属于MapActivity.此外,我没有使用片段来实现该过程.此外,我从GoogleDeveloperConsole获得了一个api密钥,并启用了一些与地点和地图相关的api.这是我在androidstudio中的android清单,<?xmlversion="1.0"encoding="utf-8"?><manif

我试图在线性布局中实现MapVIEw,这个布局不属于MapActivity.此外,我没有使用片段来实现该过程.

此外,我从Google Developer Console获得了一个API密钥,并启用了一些与地点和地图相关的API.

这是我在android studio中的androID清单,

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"    package="sec.asdf_solutions.biz.security">    <uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION" />    <uses-permission androID:name="androID.permission.ACCESS_COARSE_LOCATION" />    <uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" />    <uses-permission androID:name="androID.permission.INTERNET" />    <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" />    <uses-feature        androID:glEsversion="0x00020000"        androID:required="true" />    <application        androID:allowBackup="true"        androID:icon="@mipmap/logo"        androID:label="@string/app_name"        androID:supportsRtl="true"        androID:theme="@style/Apptheme">        <uses-library androID:name="com.Google.androID.maps" />        <activity androID:name=".SplashScreenActivity">            <intent-filter>                <action androID:name="androID.intent.action.MAIN" />                <category androID:name="androID.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity androID:name=".LoginActivity"></activity>        <activity            androID:name=".Rosteractivity"            androID:configChanges="locale"            androID:label=""            androID:theme="@style/Apptheme.light" />        <Meta-data            androID:name="com.Google.androID.gms.version"            androID:value="@integer/Google_play_services_version" />                <Meta-data            androID:name="com.Google.androID.maps.v2.API_KEY"            androID:value="@string/API_key" />            </application></manifest>

这是我的布局文件

<?xml version="1.0" enCoding="utf-8"?><relativeLayout 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/content_roster_layout"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:layout_marginBottom="5dp"    androID:layout_margintop="3dp"    app:layout_behavior="@string/appbar_scrolling_vIEw_behavior"    tools:context=".Rosteractivity"    tools:showIn="@layout/app_bar_roster">    <ScrollVIEw        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent">        <linearLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:layout_marginleft="5dp"            androID:layout_marginRight="5dp"            androID:orIEntation="vertical">            <com.Google.androID.gms.maps.MapVIEw                androID:ID="@+ID/roster_map_vIEw"                androID:layout_wIDth="match_parent"                androID:layout_height="300dp"                androID:APIKey="xxx--yyy-zzz-aaa-www"                androID:layout_weight="1"/>            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_below="@+ID/roster_map_vIEw"                androID:layout_margintop="4dp"                androID:layout_marginBottom="15dp"                androID:Alpha="0.5"                androID:background="#765491"                androID:orIEntation="vertical">                <TextVIEw                    androID:ID="@+ID/roster_ac_date_text"                    androID:layout_wIDth="match_parent"                    androID:layout_height="36dp"                    androID:layout_gravity="center"                    androID:background="#563e6b"                    androID:paddingtop="5dp"                    androID:paddingBottom="5dp"                    androID:text="5 th MAY 2017"                    androID:textStyle="bold"                    androID:textAlignment="center"                    androID:textcolor="@androID:color/white"                    androID:textSize="22sp" />                <linearLayout                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:layout_margintop="10dp"                    androID:orIEntation="horizontal">                    <TextVIEw                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:layout_weight="1"                        androID:text="START TIME"                        androID:textStyle="bold"                        androID:textAlignment="center"                        androID:textcolor="@androID:color/white"                        androID:textSize="14sp" />                    <TextVIEw                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:layout_weight="1"                        androID:text="END TIME"                        androID:textStyle="bold"                        androID:textAlignment="center"                        androID:textcolor="@androID:color/white"                        androID:textSize="14sp" />                </linearLayout>                <linearLayout                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:orIEntation="horizontal">                    <TextVIEw                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:layout_weight="1"                        androID:ID="@+ID/roster_st_time_text"                        androID:text="08.30 AM"                        androID:textStyle="bold"                        androID:textAlignment="center"                        androID:textcolor="@androID:color/white"                        androID:textSize="20sp" />                    <TextVIEw                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:layout_weight="1"                        androID:ID="@+ID/roster_ed_time_text"                        androID:text="05.30 PM"                        androID:textStyle="bold"                        androID:textAlignment="center"                        androID:textcolor="@androID:color/white"                        androID:textSize="20sp" />                </linearLayout>                <TextVIEw                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:ID="@+ID/roster_location_text"                    androID:layout_marginRight="35dp"                    androID:layout_marginleft="35dp"                    androID:layout_margintop="8dp"                    androID:drawablepadding="5dp"                    androID:drawableleft="@drawable/ic_place_small"                    androID:textAlignment="center"                    androID:maxlines="3"                    androID:lines="3"                    androID:clickable="true"                    androID:textSize="14sp"                    androID:text="Australian Strategic Partnership\n#9, School Lane, Kollpity, Colombo 3"                    androID:textcolor="@androID:color/white" />                <linearLayout                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:layout_margintop="18dp"                    androID:orIEntation="horizontal">                    <androID.support.v7.Widget.AppCompatbutton                        androID:ID="@+ID/roster_accept_btn"                                                androID:layout_height="32dp"                        androID:background="@color/logincolor"                        androID:layout_marginBottom="10dp"                        androID:layout_marginleft="10dp"                        androID:layout_marginRight="40dp"                        androID:textSize="16sp"                        androID:textStyle="bold"                        androID:layout_weight="1"                        androID:clickable="true"                        androID:text="ACCEPT" />                    <androID.support.v7.Widget.AppCompatbutton                        androID:ID="@+ID/roster_reject_btn"                                                androID:layout_height="32dp"                        androID:background="@color/acceptedPurpleColour"                        androID:layout_marginBottom="10dp"                        androID:layout_marginleft="40dp"                        androID:layout_marginRight="10dp"                        androID:textSize="16sp"                        androID:textStyle="bold"                        androID:clickable="true"                        androID:layout_weight="1"                        androID:text="REJECT" />                </linearLayout>            </linearLayout>        </linearLayout>    </ScrollVIEw></relativeLayout>

buID.gradle(模块:APP)

apply plugin: 'com.androID.application'androID {    compileSdkVersion 23    buildToolsversion '25.0.0'    defaultConfig {        applicationID "sec.asdf_solutions.biz.security"        minSdkVersion 18        targetSdkVersion 23        versionCode 1        versionname "1.0"    }    buildTypes {        release {            MinifyEnabled false            proguardfiles getDefaultProguardfile('proguard-androID.txt'), 'proguard-rules.pro'        }    }}dependencIEs {    compile filetree(dir: 'libs', include: ['*.jar'])    compile 'com.androID.support:appcompat-v7:23.4.0'    compile 'com.androID.support:design:23.4.0'    compile 'com.prolificinteractive:material-calendarvIEw:1.4.3'    compile 'com.Google.androID.gms:play-services-maps:10.2.1'    compile 'de.hdodenhof:circleimagevIEw:2.1.0'    compile 'com.squareup.retrofit2:retrofit:2.3.0'    compile 'com.squareup.retrofit2:converter-gson:2.3.0'    compile 'joda-time:joda-time:2.9.4'    compile 'com.auth0.androID:jwtdecode:1.1.0'    compile 'com.androID.support.constraint:constraint-layout:1.0.2'    compile 'com.Google.androID.gms:play-services-location:10.2.1'    compile 'com.androID.support:support-annotations:24.2.0'    compile 'com.Google.firebase:firebase-messaging:10.2.0'    compile 'com.Google.maps:Google-maps-services:0.1.20'    testCompile 'junit:junit:4.12'}apply plugin: 'com.Google.gms.Google-services'

这是我执行上述过程的活动,

public class Rosteractivity extends AppCompatActivity implements NavigationVIEw.OnNavigationItemSelectedListener {    //protected MapVIEw mMapVIEw;    androID.support.v7.Widget.AppCompatbutton acceptbutton;    androID.support.v7.Widget.AppCompatbutton rejectbutton;    private Context context;    private String token;    private long IDLong;    private Response responseBody;    TextVIEw rosterDateTextVIEw;    TextVIEw rosterStartTimeTextVIEw;    TextVIEw rosterEndTimeTextVIEw;    TextVIEw rosterLocationTextVIEw;    VIEw mainVIEw;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_roster);        Toolbar toolbar = (Toolbar) findVIEwByID(R.ID.toolbar_roster);        setSupportActionbar(toolbar);        getSupportActionbar().setdisplayShowHomeEnabled(true);    }    @OverrIDe    public boolean onNavigationItemSelected(MenuItem item) {        return true;    }}

特别注意:我没有使用MapActivity.

有什么想法吗?

解决方法:

每MapView’s documentation:

Users of this class must forward all the life cycle methods from the Activity or Fragment containing this vIEw to the corresponding ones in this class. In particular, you must forward on the following methods:

onCreate(Bundle)onStart()onResume()onPause()onStop()onDestroy()onSaveInstanceState()onLowMemory()

MapFragment或SupportMapFragment所做的就是将所有这些回调转发给MapVIEw,所以如果你自己完成这项工作,就不需要有特定的超类.

例如:

MapVIEw rosterMapVIEw;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_roster);    Toolbar toolbar = (Toolbar) findVIEwByID(R.ID.toolbar_roster);    setSupportActionbar(toolbar);    getSupportActionbar().setdisplayShowHomeEnabled(true);    rosterMapVIEw = (MapVIEw) findVIEwByID(R.ID.roster_map_vIEw);    rosterMapVIEw.onCreate(savedInstanceState);}@OverrIDeprotected voID onPause() {{    super.onPause();    rosterMapVIEw.onPause();}

等等 – 覆盖每个方法并将调用传递给MapVIEw.

总结

以上是内存溢出为你收集整理的java – Android:如何在不使用地图活动的情况下实现com.google.android.gms.maps.MapView全部内容,希望文章能够帮你解决java – Android:如何在不使用地图活动的情况下实现com.google.android.gms.maps.MapView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115237.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存