Maxouille
Maxouille

Reputation: 2911

MapView take all my screen

I searched on StackOverflow and i have no solution to my problem.

My MapView is taking all of my screen. I used weights but noway, it doesn't work. It work on AVD by the way ! This is so wird ^^

I have one map.clear() in my java code. Is it possible is that ?

There is my xml file :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

     <FrameLayout 
        android:id="@+id/map_frame"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.30" > 
            <fragment
                android:id="@+id/mapView"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                />
    </FrameLayout>

    <LinearLayout
        android:id="@+id/list_establishments"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.7"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:text="Truc 1" />

        <TextView
            android:id="@+id/text2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Truc 2"
            android:layout_weight="0.3" />

        <TextView
            android:id="@+id/text3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Truc 3"
            android:layout_weight="0.3" />

    </LinearLayout>

</LinearLayout>

Upvotes: 0

Views: 64

Answers (2)

Jo&#227;o Marcos
Jo&#227;o Marcos

Reputation: 3972

Use

<com.google.android.gms.maps.MapView
                android:id="@+id/map_detail"
                android:layout_width="match_parent"
                android:layout_height="246dp" />

instead of fragment to create map layout.

In your java fragment class use this code to initialize the map:

MapsInitializer.initialize(getActivity());      
MapView mapView = (MapView) v.findViewById(R.id.map_detail);
mapView.onCreate(savedInstanceState);
if(mapView!=null){
  GoogleMap map = mapView.getMap();
}

Upvotes: 0

AlonsoFloo
AlonsoFloo

Reputation: 523

Try this :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

 <FrameLayout 
    android:id="@+id/map_frame"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.30" > 
        <fragment
            android:id="@+id/mapView"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />
</FrameLayout>

<LinearLayout
    android:id="@+id/list_establishments"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_weight="0.7"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.3"
        android:text="Truc 1" />

    <TextView
        android:id="@+id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Truc 2"
        android:layout_weight="0.3" />

    <TextView
        android:id="@+id/text3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Truc 3"
        android:layout_weight="0.3" />

</LinearLayout>

It doesn't work because you are using fill_parent as the height. The weight is used to distribute the remaining empty space or take away space when the total sum is larger than the LinearLayout. Set your widths to 0dip instead and it will work.

Upvotes: 2

Related Questions