마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

google mapview 사이즈 조정

0 추천

화면안에 출발지와 배송지 각각 지도를 넣으려고 합니다.

출발지 버튼을 클릭하면 밑에 출발지 지도가 나오고,

배송지 버튼을 클릭하면 밑에 배송지 지도가 나오는 화면입니다.

 

그런데 구글 map view를 fragment로 붙이니 아래 width ->  height 전체를 다 사용해버리네요.

width -> height 를 넣어봤는데도 안되고 전체를 차지해버리니 밑에 버튼들이나 레이아웃이 다 사라져보러네요.

 

일정한 퍼센트나 크기로 지도가 보이게 하려면 어떻게 해야하는지 도움 부탁드립니다.

 

activity_main.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: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="com.rocketlaunch.quickmon.activity.MainActivity" >
            
   <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    	        
	    <LinearLayout
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:orientation="horizontal">    	
		   <TextView
		        android:layout_width="wrap_content"
		        android:layout_height="wrap_content"
		        android:text="출발지 선택" />

	    	<Button
		        android:id="@+id/btnSearchDepart"
		        android:layout_width="wrap_content"
		        android:layout_height="wrap_content"
		        android:layout_gravity="right"
		        android:text="선택"/>
    	</LinearLayout>
    	
	    <LinearLayout
	        android:id="@+id/fragment_container"
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:orientation="vertical">
	    </LinearLayout>
	    	    
	    <LinearLayout
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:orientation="horizontal">    	
		    <TextView
		        android:layout_width="wrap_content"
		        android:layout_height="wrap_content"
		        android:text="도착지 선택" />

	    	<Button
		        android:id="@+id/btnSearchDest"
		        android:layout_width="wrap_content"
		        android:layout_height="wrap_content"
		        android:layout_gravity="right"
		        android:text="선택"/>
    	</LinearLayout>	    
    	
	    <LinearLayout
	        android:id="@+id/fragment_container2"
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:orientation="vertical">
	    </LinearLayout>
	    	    

	   <Button
	        android:id="@+id/btnCall"
	        android:layout_width="match_parent"
	        android:layout_height="wrap_content"
	        android:text="길찾기"/>	    
    </LinearLayout>       
</RelativeLayout>

 

activity_map_view.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    
    <com.google.android.gms.maps.MapView 
        android:id="@+id/mapview"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" />

</LinearLayout>

 

MainActivity.java

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends FragmentActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_main);

		Button btnFrag1 = (Button)findViewById(R.id.btnSearchDepart);
		btnFrag1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                MapViewFragment frag1 = new MapViewFragment();
                fragmentTransaction.add(R.id.fragment_container, frag1, "frag1");
                fragmentTransaction.commit();
			}
		});
		
		Button btnFrag2 = (Button)findViewById(R.id.btnSearchDest);
		btnFrag2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                MapViewFragment frag2 = new MapViewFragment();
                fragmentTransaction.add(R.id.fragment_container2, frag2, "frag2");
                fragmentTransaction.commit();
			}
		});		
	}
}

 

MapViewFragment.java

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.LatLng;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MapViewFragment extends Fragment {
	MapView mapView;
	GoogleMap map;
 
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.activity_map_view, container, false);
 
 		// Gets the MapView from the XML layout and creates it
		mapView = (MapView) v.findViewById(R.id.mapview);
		mapView.onCreate(savedInstanceState);
 
		// Gets to GoogleMap from the MapView and does initialization stuff
		map = mapView.getMap();
		map.getUiSettings().setMyLocationButtonEnabled(false);
		map.setMyLocationEnabled(true);

		// Needs to call MapsInitializer before doing any CameraUpdateFactory calls
		try {
			MapsInitializer.initialize(this.getActivity());
//		} catch (GooglePlayServicesNotAvailableException e) {
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// Updates the location and zoom of the MapView
		CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
		map.animateCamera(cameraUpdate);
		
 
		return v;
	}

	@Override
	public void onResume() {
		mapView.onResume();
		super.onResume();
	}
 
	@Override
	public void onDestroy() {
		super.onDestroy();
		mapView.onDestroy();
	}
 
	@Override
	public void onLowMemory() {
		super.onLowMemory();
		mapView.onLowMemory();
	}
}

 

두리치치 (180 포인트) 님이 2015년 12월 4일 질문
두리치치님이 2015년 12월 4일 수정

1개의 답변

+1 추천
 
채택된 답변

activity_map_view.xml에서 아래 형광색 된 부분을 변경하셔야 합니다. 예를 들어, "200dp"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content">

     

    <com.google.android.gms.maps.MapView

        android:id="@+id/mapview"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content" />

 

</LinearLayout>

cc1232 (35,280 포인트) 님이 2015년 12월 4일 답변
두리치치님이 2015년 12월 8일 채택됨
감사합니다. width아니라 height라서 다시 수정했습니다.
혹시 퍼센트로 넣을수도 있는건가요?
LinearLayout에는 layout_weight라는 게 있습니다. 퍼센트는 아니지만, 퍼센트와 유사하게 적용하실 수 있을 겁니다. layout_weight를 찾아보시고 적용해보세요
넵~ 정말 감사합니다!!!
...