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

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

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

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

Android Studio

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

Android Emulator

Android EmulatorはアンドロイドのOSで起動しているアンドロイドのデバイスの機能をシミュレートするソフトウェアです。Emulatorは開発者に複数の違う設定を持ったデバイスを必要とすることなくアプリケーションを開発しテストすることが可能になります。

Q&A

解決済

1回答

3444閲覧

Fragmentのサイズを変更したい

Eston

総合スコア67

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

Android Studio

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

Android Emulator

Android EmulatorはアンドロイドのOSで起動しているアンドロイドのデバイスの機能をシミュレートするソフトウェアです。Emulatorは開発者に複数の違う設定を持ったデバイスを必要とすることなくアプリケーションを開発しテストすることが可能になります。

0グッド

0クリップ

投稿2020/08/16 01:21

編集2020/08/16 01:23

いつもお世話になっております

現在、下記の画像のような、ロケーションを検索できる機能を作成しております
まだ、レイアウト段階なのですげ、GoogleMapsFragmentのサイズ変更ができず困っています

右クリック->New->Google->Google Maps ActivityでMapsActivityを作成後、android:layoutでレイアウトを変えたのですが、エミュレーター上では変化が観られません

Fragmentの扱いが違うのは理解しているのですが、目標物のようにちょうどよいサイズで配置するにはどうしたら良いでしょうか?
ご助力いただけると助かります

目標物

現在のエミュレーター画面

Android Studio内

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コード

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

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

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

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

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

guest

回答1

0

ベストアンサー

Mapを表示するFragmentを縮小し、かつ任意の位置に配置したいのであれば、Layout系のコンポーネントの内側にFragmentを配置して調整する必要があります。

例えば、ConstraintLayoutを用いれば次のようなコードでだいたい近いイメージになるのではないかと思います。

xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MapsActivity"> 8 9 <androidx.constraintlayout.widget.Guideline 10 android:id="@+id/guideline1" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:orientation="horizontal" 14 app:layout_constraintGuide_percent="0.6" /> 15 16 <androidx.constraintlayout.widget.Guideline 17 android:id="@+id/guideline2" 18 android:layout_width="wrap_content" 19 android:layout_height="wrap_content" 20 android:orientation="horizontal" 21 app:layout_constraintGuide_percent="0.9" /> 22 23 <fragment 24 android:id="@+id/map" 25 android:name="com.google.android.gms.maps.SupportMapFragment" 26 android:layout_width="0dp" 27 android:layout_height="0dp" 28 app:layout_constraintBottom_toTopOf="@+id/guideline2" 29 app:layout_constraintEnd_toEndOf="parent" 30 app:layout_constraintStart_toStartOf="parent" 31 app:layout_constraintTop_toTopOf="@+id/guideline1" /> 32 33</androidx.constraintlayout.widget.ConstraintLayout>

これは上から60%と90%の2箇所に水平ガイドラインを引いて、それに挟まれたところにFragmentを配置したものです。他にもいろいろ方法はあるでしょうが、いずれにしてもこのようにして何らかのLayoutの中にFragmentを配置して調整することになるでしょう。

イメージ説明

投稿2020/08/16 01:58

keicha_hrs

総合スコア6766

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

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

Eston

2020/08/17 19:53

丁寧な説明と具体的なコード付きの解答ありがとうございます。ConstraintLayoutについて知識がなかったので、勉强になりました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問