Search code examples
javaandroidgoogle-maps-api-2

Google Map V2 on Top half of the android screen and list view on the bottom half of the android screen


I am working on a Android project in which I need to show Google Map v2 on top half of the Android Screen and in the bottom half of the same android screen, I need to show a ListView.

Below is the code, I have so far which will be launched as soon as I launch my Application. I have setup properly the AndroidManifest.xml file for Google Map V2 key.

public class SampleActivity extends Activity {

    @TargetApi(11)
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sample);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().hide();
        }
        findViewById(R.id.sample_button).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int width = (int) TypedValue.applyDimension(
                                TypedValue.COMPLEX_UNIT_DIP, 40, getResources()
                                .getDisplayMetrics());
                        SlideoutActivity.prepare(SampleActivity.this,
                                R.id.inner_content, width);
                        startActivity(new Intent(SampleActivity.this,
                                MenuActivity.class));
                        overridePendingTransition(0, 0);
                    }
                });
    }

}

And below is the sample.xml file which I need to modify so that I can add stuff which will have Google Map v2 in top half of the android screen and in the bottom half, I will have ListView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/inner_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_android" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:paddingLeft="2dip"
        android:paddingRight="2dip"
        android:background="#bb000000">

        <Button style="@android:style/Widget.Button.Small"
            android:id="@+id/sample_button"
            android:layout_width="35dip"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dip"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:text=">" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/sample_button"
            android:layout_centerVertical="true"
            android:textSize="19sp"
            android:textColor="#ffffff"
            android:text="Facebook-like slide-out nav"/>
    </RelativeLayout>

</RelativeLayout>

Can anyone help me with this? I am done with all my settings related to setting up the Google Map API v2 key. I just need to plugin the code to start showing the google map v2 on the TOP half of the android screen and list view on the bottom half of the android screen.

Any help will be appreciated on this. Thanks

Update:-

Will this updated XML file will work to have Google Map v2 on top half of the android screen and ListView on bottom half of the android screen?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/inner_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_android" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:background="#bb000000"
        android:paddingLeft="2dip"
        android:paddingRight="2dip" >

        <Button
            android:id="@+id/sample_button"
            style="@android:style/Widget.Button.Small"
            android:layout_width="35dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dip"
            android:text=">" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/sample_button"
            android:text="Proximity Application"
            android:textColor="#ffffff"
            android:textSize="19sp" />
    </LinearLayout>

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

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.8"
        android:orientation="horizontal" >

        <ListView
            android:id="@+id/mylist"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" >
        </ListView>
    </LinearLayout>

</LinearLayout>

Solution

  • This layout should present you a map in the top half of the screen an a ListView in the bottom half:

    <?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" >
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:orientation="vertical" >
    
         <fragment
            xmlns:map="http://schemas.android.com/apk/res-auto"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:orientation="vertical" >
    
        <ListView 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/list">          
        </ListView>
    </LinearLayout>
    
    </LinearLayout>