I have an XML layout that has a google map, two text views, and a button in a relative layout. The text views are below the google map with the text values "Latitude:" and "Longitude:" that get updated to "Latitude:xxx" and "Longitude"xxx" when the user moves the cursor on the map. The submit button says "Submit" and does just that, it packages lat/lon in an intent and passes it to the next activity.
This was all fine until I started messing with the layout. I noticed that because I had lazily been using the Graphical design tool in eclipse, everything had set dimensions, meaning on bigger screens it looked silly.
I added another relative layout and placed the lat/long texts and the submit button into it, and placed the new layout under the other relative layout that now only has the MapView.
My intent was to use android:layout_weight to assign the bottom relative layout around 15% or so of the screen on the botton, and the rest of the screen would be the google map.
Physically the dimensions were fine. However if I had the textviews dependant on the submit button at all (android:layout_above/below), the submit button's text would take on the value of the textview dependant on it and would get updated, while the textview would be stuck at "lat/long:" and would not get updated.
I currently have the textviews just set at the top of the relative layout and the independent submit button on the bottom and it works fine. I was just curious as to what the heck was happening.
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="80" >
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="xxx"
android:clickable="true"
android:enabled="true" >
</com.google.android.maps.MapView>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="20" >
<TextView
android:id="@+id/Latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Latitude:" />
<TextView
android:id="@+id/Longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/Latitude"
android:text="Longitude:" />
<Button
android:id="@+id/submitbutton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="GOTOUPLOADER"
android:text="Submit" />
</RelativeLayout>
And here is the only (i think) relevant code that works with this xml file. Notice that I don't do anything with the button text here. It isn't even an attribute in this class. The only interaction the button has with this class is that it calls a method to start another activity when it is clicked.
//setupmap()instantiates mapview and centers on the given location
public void setupmap()
{
getcoords();//setup coordinates
lattext.setText("Latitude: "+String.valueOf(Lat));
lontext.setText("Longitude: "+String.valueOf(Long));
mapView = (MapView) findViewById(R.id.mapView);//instantiate mapview
mapView.setBuiltInZoomControls(true);//able to zoom
mcontrol = mapView.getController();//mapcontroller contains methods to manipulate mapview
mcontrol.animateTo(point);//zoom to our geopoint
mcontrol.setZoom(19);//zoom level 1-21. 1=world view, 21=as zoomed in as possible
MyOverlay over = new MyOverlay();//instantiate overlay
listofoverlays = mapView.getOverlays();//create a list of overlays
listofoverlays.clear();//clear list
listofoverlays.add(over);//add our overlay
mapView.invalidate();//invalidate for changes to take effect
}//setupmap
Please forgive all the comments.
</LinearLayout>. And also the MapViewandroid:enabled="true"is deprecated, useandroid:state_enabled="true"