AndroidStudio初心者です。
現在、MapsActivityを選択すると作られプログラムを元にして、自分でConstraintLayoutを使い、画像と地図を一つの画面に表示させるように書いてみました。
しかし、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
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。