質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

452閲覧

【Google Map API】画像と地図を一つの画面に表示させたい

yuyu213

総合スコア17

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2019/01/08 14:47

編集2019/01/08 16:38

AndroidStudio初心者です。
現在、MapsActivityを選択すると作られプログラムを元にして、自分でConstraintLayoutを使い、画像と地図を一つの画面に表示させるように書いてみました。
しかし、Designの画面では画像が表示されているのに、エミュレータで実行すると地図だけが表示され、画像が表示されず、余白になってしまいます。
お教授の程、よろしくお願い致します。
読みにくいコードですみません。

Design画面
エミュレータの実行結果


activity_maps.xml

xml

1<?xml version="1.0" encoding="utf-8"?> 2 3<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 xmlns:tools="http://schemas.android.com/tools" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent"> 8 9 10 <ImageView 11 android:id="@+id/imageView" 12 android:layout_width="0dp" 13 android:layout_height="60dp" 14 android:contentDescription="@string/yhui" 15 android:scaleType="centerCrop" 16 app:layout_constraintBottom_toTopOf="@+id/map" 17 app:layout_constraintEnd_toEndOf="parent" 18 app:layout_constraintStart_toStartOf="parent" 19 app:layout_constraintTop_toTopOf="parent" 20 app:srcCompat="@drawable/jppa" /> 21 22 23 24 <fragment xmlns:android="http://schemas.android.com/apk/res/android" 25 xmlns:map="http://schemas.android.com/apk/res-auto" 26 xmlns:tools="http://schemas.android.com/tools" 27 android:id="@+id/map" 28 android:name="com.google.android.gms.maps.SupportMapFragment" 29 android:layout_width="match_parent" 30 android:layout_height="0dp" 31 map:layout_constraintBottom_toBottomOf="parent" 32 map:layout_constraintEnd_toEndOf="parent" 33 map:layout_constraintHorizontal_bias="0.0" 34 map:layout_constraintStart_toStartOf="parent" 35 map:layout_constraintTop_toBottomOf="@+id/imageView" 36 tools:context=".MapsActivity" /> 37 38 39 40</android.support.constraint.ConstraintLayout>

MapsActivity

java

1package com.example.yuyu.tdsexpeditonmap; 2 3import android.support.v4.app.FragmentActivity; 4import android.os.Bundle; 5import android.support.v7.app.AlertDialog; 6 7import com.google.android.gms.maps.CameraUpdate; 8import com.google.android.gms.maps.CameraUpdateFactory; 9import com.google.android.gms.maps.GoogleMap; 10import com.google.android.gms.maps.OnMapReadyCallback; 11import com.google.android.gms.maps.SupportMapFragment; 12import com.google.android.gms.maps.model.LatLng; 13import com.google.android.gms.maps.model.Marker; 14import com.google.android.gms.maps.model.MarkerOptions; 15import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener; 16 17 18public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 19 20 private GoogleMap mMap; 21 22 protected void onCreate (Bundle savedInstanceState){ 23 super.onCreate(savedInstanceState); 24 setContentView(R.layout.activity_maps); 25 // Obtain the SupportMapFragment and get notified when the map is ready to be used. 26 SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 27 .findFragmentById(R.id.map); 28 mapFragment.getMapAsync(this); 29 } 30 31 32 33 @Override 34 public void onMapReady(GoogleMap googleMap) { 35 mMap = googleMap; 36 37 // Add a marker in Sydney and move the camera 38 LatLng sydney = new LatLng(-34, 151); 39 mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 40 mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 41 42 CameraUpdate cUpdate = CameraUpdateFactory.newLatLngZoom( 43 new LatLng(35.626653, 139.887767), 17); 44 mMap.moveCamera(cUpdate); 45 46 47 48 49 new AlertDialog.Builder(this) 50 .show(); 51 52 53 54 55 mMap.addMarker(new MarkerOptions().position(new LatLng(35.626653, 139.887767))) ; 56 mMap.addMarker(new MarkerOptions().position(new LatLng(35.626653, 139.887600))) ; 57 58 59 mMap.setOnMarkerClickListener(new OnMarkerClickListener() { 60 @Override 61 public boolean onMarkerClick(Marker marker) { 62 63 String id = marker.getId(); 64 65 if (id.equals("m2")) { 66 new AlertDialog.Builder(MapsActivity.this) 67 .show(); 68 } else if (id.equals("m1")) { 69 new AlertDialog.Builder(MapsActivity.this) 70 .show(); 71 } 72 73 return false; 74 } 75 }); 76 77 78 } 79 80} 81

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

fragment側で

xml

1 map:layout_constraintBottom_toBottomOf="parent"

のようにmap:から始まっているものは、app:の誤りではないでしょうか。そのために正しく制約できていない可能性があると思います。

後は、実行しようとしている端末の画面サイズと、@drawable/jppaで指定される画像のサイズの関係は問題ないでしょうか。ImageViewで

xml

1 android:scaleType="centerCrop"

となっていますが、画像サイズの比率次第では画面からはみ出てしまう可能性がないでしょうか。スケーリングのためにはみ出た余白部分しか見えていないのかも?

投稿2019/01/09 13:33

keicha_hrs

総合スコア6766

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問