Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我希望在我的相对布局中有一个包含imageView和TextView的mapView_Android_Android Mapview_Android Relativelayout - Fatal编程技术网

Android 我希望在我的相对布局中有一个包含imageView和TextView的mapView

Android 我希望在我的相对布局中有一个包含imageView和TextView的mapView,android,android-mapview,android-relativelayout,Android,Android Mapview,Android Relativelayout,要获得MapView,我必须使用MapActivity扩展我的类。当我尝试这样做时,我得到一个错误“CreateMapActivity类” 如果我不使用MapActivity扩展它,而是使用Activity,则会出现以下异常 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.strive.gostrive/com.strive.gostrive.EventDetailActivity}: android.

要获得MapView,我必须使用MapActivity扩展我的类。当我尝试这样做时,我得到一个错误“CreateMapActivity类”

如果我不使用MapActivity扩展它,而是使用Activity,则会出现以下异常

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.strive.gostrive/com.strive.gostrive.EventDetailActivity}: android.view.InflateException: Binary XML file line #168: Error inflating class com.google.android.maps.MapView
我已经对xml文件、android清单文件进行了必要的更改。我的项目中还包括了谷歌播放服务库。google play服务和我的应用程序的目标是相同的

需要帮助

这是我的xml文件

<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"
android:background="@drawable/background"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".EventDetailActivity" >

<ImageView
    android:id="@+id/eventDImg"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_alignBaseline="@+id/eventDEndDate"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/innershadow" />

<TextView
    android:id="@+id/textView2D"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDDateTV"
    android:layout_alignBottom="@+id/eventDDateTV"
    android:layout_toRightOf="@+id/eventDDateTV"
    android:text="-" />

<TextView
    android:id="@+id/eventDEndDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2D"
    android:layout_toRightOf="@+id/textView2D"
    android:maxLength="10"
    android:text="End Date" />

<TextView
    android:id="@+id/eventDStartAge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDEndDate"
    android:layout_alignLeft="@+id/textView3D"
    android:layout_marginLeft="39dp"
    android:maxLength="2"
    android:text="frm" />

<TextView
    android:id="@+id/textView4D"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDEndDate"
    android:layout_toRightOf="@+id/eventDStartAge"
    android:text="-" />

<TextView
    android:id="@+id/eventDAgeTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDEndDate"
    android:layout_toRightOf="@+id/textView4D"
    android:maxLength="2"
    android:text="to" />

<TextView
    android:id="@+id/eventDTitleTV"
    android:layout_width="180dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="48dp"
    android:maxLines="2"
    android:text="Event Title"
    android:textSize="20dp" />

<TextView
    android:id="@+id/eventDDateTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/eventDTitleTV"
    android:layout_centerVertical="true"
    android:maxLength="10"
    android:text="Strt Date" />

<TextView
    android:id="@+id/textView1D"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDTitleTV"
    android:layout_marginLeft="180dp"
    android:layout_toLeftOf="@+id/eventDPriceTV"
    android:text="$"
    android:textSize="20dp" />

<TextView
    android:id="@+id/textView3D"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/eventDDayTV"
    android:layout_alignBaseline="@+id/eventDEndDate"
    android:layout_marginLeft="23dp"
    android:layout_toRightOf="@+id/eventDTitleTV"
    android:text="Ages:" />

<TextView
    android:id="@+id/eventDPriceTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView1D"
    android:layout_alignBottom="@+id/textView1D"
    android:layout_alignLeft="@+id/textView3D"
    android:text="Event Fee"
    android:textSize="20dp" />

<TextView
    android:id="@+id/eventDStrtTime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/eventDDayTV"
    android:layout_marginTop="16dp"
    android:text="Strt Tym" />

<TextView
    android:id="@+id/eventDEndTime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDStrtTime"
    android:layout_alignLeft="@+id/eventDEndDate"
    android:layout_marginLeft="26dp"
    android:text="End tym" />

<TextView
    android:id="@+id/eventDVenueTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDEndTime"
    android:layout_alignLeft="@+id/eventDGender"
    android:text="Venue" />

<TextView
    android:id="@+id/eventDDayTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/eventDImg"
    android:layout_below="@+id/eventDDateTV"
    android:layout_marginTop="31dp"
    android:text="M Tu W" />

<TextView
    android:id="@+id/eventDGender"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/eventDDayTV"
    android:layout_alignBottom="@+id/eventDDayTV"
    android:layout_toRightOf="@+id/textView1D"
    android:text="gender" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="150dp"
    android:layout_alignLeft="@+id/eventDImg"
    android:layout_alignRight="@+id/eventDImg"
    android:layout_below="@+id/eventDImg"
    android:layout_marginTop="16dp"
    android:orientation="vertical" >


    <com.google.android.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="***************************"
        android:clickable="true" />
</LinearLayout>

您可以改用MapFragment。这样,您就不需要扩展MapActivity。


要与较低版本一起使用,可以使用。要使用此类,必须在构建路径中包含Android支持库。

这里是一个工作活动,在RelativeLayout中有一个MapView

要显示地图,请在Google API上创建项目,启用地图API,创建凭据,将密钥复制到您的应用程序中

src/debug/res/values/google_maps.xml
src/release/res/values/google_maps.xml
在应用程序内更新AndroidManifest.xml

    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/.
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

<activity android:name=".MapActivity"/>

您是否应该在布局文件中使用View class
com.google.android.gms.maps.MapView
?您的意思是在布局文件中使用@harism而不是activity class?,因为maps v2
MapView
已移动到
com.google.android.gms.maps
包中。不再是
com.google.android.maps
。@harism我正在我的活动中导入com.google.android.gms.maps.MapView。但是你的布局文件遗漏了
.gms.
部分,尽管我怀疑你的布局膨胀失败了。
    <!--
         The API key for Google Maps-based APIs is defined as a string resource.
         (See the file "res/values/google_maps_api.xml").
         Note that the API key is linked to the encryption key used to sign the APK.
         You need a different API key for each encryption key, including the release key that is used to
         sign the APK for publishing.
         You can define the keys for the debug and release targets in src/debug/ and src/release/.
    -->
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

<activity android:name=".MapActivity"/>
package au.com.derpapps.derpapp;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.RelativeLayout;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;

public class MapActivity extends Activity implements OnMapReadyCallback  {

    // Private variables

    private MapView mapView;
    private GoogleMap googleMap;

    // Activity methods

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        RelativeLayout relativeLayout = new RelativeLayout(this);
        relativeLayout.setBackgroundColor(Color.WHITE);

        mapView = new MapView(this);
        mapView.onCreate(savedInstanceState);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.setMargins(200, 200, 200, 200);
        mapView.setLayoutParams(layoutParams);
        relativeLayout.addView(mapView);
        setContentView(relativeLayout);

        mapView.getMapAsync(this);

    }

    public void onMapReady(GoogleMap googleMap) {
        this.googleMap = googleMap;

        mapView.onResume();
    }

}