いつもお世話になっております
現在、下記の画像のような、ロケーションを検索できる機能を作成しております
まだ、レイアウト段階なのですげ、GoogleMapsFragmentのサイズ変更ができず困っています
右クリック->New->Google->Google Maps ActivityでMapsActivityを作成後、android:layoutでレイアウトを変えたのですが、エミュレーター上では変化が観られません
Fragmentの扱いが違うのは理解しているのですが、目標物のようにちょうどよいサイズで配置するにはどうしたら良いでしょうか?
ご助力いただけると助かります
ActivityMapsXML
1<?xml version="1.0" encoding="utf-8"?> 2<fragment xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:map="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:id="@+id/map" 6 android:name="com.google.android.gms.maps.SupportMapFragment" 7 android:layout_width="316dp" 8 android:layout_height="219dp" 9 tools:layout_editor_absoluteX="41dp" 10 tools:layout_editor_absoluteY="453dp" 11 tools:context=".MapsActivity" />
MapsActivity(変更なし)
1package com.example.myfirstapp; 2 3import androidx.fragment.app.FragmentActivity; 4 5import android.os.Bundle; 6 7import com.google.android.gms.maps.CameraUpdateFactory; 8import com.google.android.gms.maps.GoogleMap; 9import com.google.android.gms.maps.OnMapReadyCallback; 10import com.google.android.gms.maps.SupportMapFragment; 11import com.google.android.gms.maps.model.LatLng; 12import com.google.android.gms.maps.model.MarkerOptions; 13 14public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 15 16 private GoogleMap mMap; 17 18 @Override 19 protected void onCreate(Bundle savedInstanceState) { 20 super.onCreate(savedInstanceState); 21 setContentView(R.layout.activity_maps); 22 // Obtain the SupportMapFragment and get notified when the map is ready to be used. 23 SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 24 .findFragmentById(R.id.map); 25 mapFragment.getMapAsync(this); 26 } 27 28 /** 29 * Manipulates the map once available. 30 * This callback is triggered when the map is ready to be used. 31 * This is where we can add markers or lines, add listeners or move the camera. In this case, 32 * we just add a marker near Sydney, Australia. 33 * If Google Play services is not installed on the device, the user will be prompted to install 34 * it inside the SupportMapFragment. This method will only be triggered once the user has 35 * installed Google Play services and returned to the app. 36 */ 37 @Override 38 public void onMapReady(GoogleMap googleMap) { 39 mMap = googleMap; 40 41 // Add a marker in Sydney and move the camera 42 LatLng sydney = new LatLng(-34, 151); 43 mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 44 mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 45 } 46} 47コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/17 19:53