user3485470
user3485470

Reputation: 131

Make google map not full screen android app

I am trying to implement an app that shows a map with a few textfields under it and a few buttons.

But when I open the app the entire screen space is taken in by the map. Is there a way so all the objects fill the screen nicely without not hiding one?

This is the code from the activity_main xml file :

<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" />

I have already tried changing the map width and height from match_parent to wrap_content and it still isn't working.

This is the code from the 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);
            }
        });
    } 
}

Any help would be greatly appreciated.

Upvotes: 3

Views: 5319

Answers (2)

Burak Sel&#231;uk
Burak Sel&#231;uk

Reputation: 11

Build > Clean project and run again. it worked for me.

Upvotes: 0

dthomasen
dthomasen

Reputation: 826

Try to use LinearLayout and weights:

<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>

Change the weights according to your needs.

More info on weights: http://developer.android.com/guide/topics/ui/layout/linear.html#Weight

Upvotes: 7

Related Questions