Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Height MapFragment Layout not work

I'm build an app that contain two tabhost (top and botton) and in one tab, I want to put a Google Map through the Google API. All works well but the map does not display correctly. You can see better in this picture:

enter image description here

My code is:

fragment_mapa.xml

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

    <fragment 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

</RelativeLayout>

MapaFragment.java

public class MapaFragment extends Fragment {
    public MapaFragment(){}

    public GoogleMap mapa;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_mapa, container, false);

        if (container != null) {
            container.removeAllViews();
        }

        GoogleMap map = ((SupportMapFragment) getActivity().getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        ((MainActivity) getActivity()).setBar();

        //Asigno el nombre de la vista e integro tabhost-sliding
        ((MainActivity) getActivity()).setTitle("Mapa");
        ((MainActivity) getActivity()).integrationMenu();

        return rootView;

    }


    public void onDestroyView() {
        super.onDestroyView();
        Log.d("DESTROY", "onDestroyView");

        Fragment f = getActivity()
                .getSupportFragmentManager().findFragmentById(R.id.map);

        if (f != null) {
            getActivity().getSupportFragmentManager()
            .beginTransaction().remove(f).commit();
        }
    }
}

And my activity_main.xml that contain the two tabhost and a framelayout that call the fragments:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Estructura de los dos tabhost -->
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/LinearLayout1"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- TABHOST SUPERIOR -->
        <RelativeLayout
            android:id="@+id/l1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:gravity="right"
            android:layout_above="@+id/l2"
            android:layout_alignParentTop="true">

            <android.support.v4.app.FragmentTabHost
                android:id="@+id/tabhost_sup"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

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

                    <TabWidget
                        android:id="@android:id/tabs"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="50dip"
                        android:layout_weight="0"/>


                    <ScrollView 
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#ffffff">
                        <FrameLayout
                            android:id="@android:id/tabcontent"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="0"/>
                    </ScrollView>

                </LinearLayout>
            </android.support.v4.app.FragmentTabHost>
        </RelativeLayout>

        <!-- TABHOST INFERIOR -->
        <RelativeLayout
            android:id="@+id/l2"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:layout_weight="1"
            android:gravity="right"
            android:layout_alignParentBottom="true"
            android:background="@android:color/background_light" >

            <android.support.v4.app.FragmentTabHost
                android:id="@android:id/tabhost"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <LinearLayout
                    android:id="@+id/RelativeLayout1"
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <FrameLayout
                        android:id="@android:id/tabcontent"
                        android:layout_width="0dp"
                        android:layout_height="0dp"
                        android:layout_weight="0"/>

                    <TabWidget
                        android:id="@android:id/tabs"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="0" 
                        android:layout_marginBottom="0dp"/>

                </LinearLayout>
            </android.support.v4.app.FragmentTabHost>
        </RelativeLayout>
    </RelativeLayout>

    <!-- Listview to display slider menu -->
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"       
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>

    <ListView 
        android:id="@+id/right_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"       
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>

</android.support.v4.widget.DrawerLayout>
like image 739
Yeray Avatar asked Nov 30 '25 18:11

Yeray


2 Answers

Removing scrollview is not convinient solution.Instead of it try android:FillViewPort="True" for Scrollview in your layout solve your problem for all screen where you may require scroll for your activity content.Hope this helps you!!

like image 68
Sharad Mhaske Avatar answered Dec 02 '25 06:12

Sharad Mhaske


SOLUTION (by Hardik):

Remove the scrollview in my activity_main.xml and it works well.

like image 33
Yeray Avatar answered Dec 02 '25 07:12

Yeray