My layout looks like:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar">
</include>
<AutoCompleteTextView
android:id="@+id/edit_location_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/edit_location_input_hint"/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
So I use AutoCompleteTextView
at the top of the screen and the map below.
The activity code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_location);
...
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
LatLng point = new LatLng(mService.getLocation().getLatitude(), mService.getLocation().getLongitude());
mMap.addMarker(new MarkerOptions().position(point).title(mService.getName()));
mMap.moveCamera(CameraUpdateFactory.newLatLng(point));
mMap.animateCamera(CameraUpdateFactory.zoomTo(16));
}
For now everything works as expected and the marker shown at the center of the map.
But when I add extra TextView
(see below view with id edit_location_input
) below AutoCompleteTextView
like this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar">
</include>
<AutoCompleteTextView
android:id="@+id/edit_location_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/edit_location_input_hint"/>
<TextView
android:id="@+id/edit_location_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
the marker is shown not at the center of the map (actually I need to zoom and move the map to see the marker). Looks like it located nearby.
When I set fixed width to the TextView
<TextView
android:id="@+id/edit_location_result"
android:layout_width="match_parent"
android:layout_height="40dp"/>
marker appears in the center as expected.
Why does some views affect the map and how to fix it?