2014-10-08 2 views
2

Я пытаюсь реализовать приложение, которое отображает карту с несколькими текстовыми полями под ней и несколькими кнопками.Сделать google map не полноэкранным андроидным приложением

Но когда я открываю приложение, весь экран занимает карта. Есть ли способ, чтобы все объекты заполнили экран красиво, не скрывая его?

Это код из файла XML activity_main:

<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" 
tools:context=".MainActivity" > 

<fragment 
     android:id="@+id/map" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:name="com.google.android.gms.maps.MapFragment"/> 

<EditText android:id="@+id/EditTest" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="@string/EditTest" /> 

<EditText android:id="@+id/inTegerTest" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="@string/integerTest" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/ButtonTest" /> 

Я уже попытался изменить ширину карты и высоту от match_parent до wrap_content и она по-прежнему не работает.

Это код из activity_main:

private GoogleMap mMap; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    getMapSafely(); 

    if(mMap != null){ 
     mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 

     mMap.setOnMapClickListener(new OnMapClickListener() { 

      @Override 
      public void onMapClick(LatLng latLng) { 

       // Creating a marker 
       MarkerOptions markerOptions = new MarkerOptions(); 

       // Setting the position for the marker 
       markerOptions.position(latLng); 

       // Setting the title for the marker. 
       // This will be displayed on taping the marker 
       markerOptions.title(latLng.latitude + " : " + latLng.longitude); 

       // Clears the previously touched position 
       mMap.clear(); 

       // Animating to the touched position 
       mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); 

       // Placing a marker on the touched position 
       mMap.addMarker(markerOptions); 
      } 
     }); 
    } 
} 

Любая помощь будет принята с благодарностью.

ответ

6

Попробуйте использовать LinearLayout и вес:

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<fragment 
    android:id="@+id/map" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:name="com.google.android.gms.maps.MapFragment" 
    android:layout_weight="4"/> 

<EditText android:id="@+id/EditTest" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:hint="@string/EditTest" 
    android:layout_weight="1"/> 

<EditText android:id="@+id/inTegerTest" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:hint="@string/integerTest" 
    android:layout_weight="1"/> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:text="@string/ButtonTest" 
    android:layout_weight="1"/> 

</LinearLayout> 

Изменения весов в соответствии с вашими потребностями.

Дополнительная информация о весах: http://developer.android.com/guide/topics/ui/layout/linear.html#Weight

Смежные вопросы