Моя раскладка выглядит следующим образом:Android Google Map является не центром
<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>
Поэтому я использую AutoCompleteTextView
в верхней части экрана и на карте ниже.
Код деятельности:
@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));
}
Для теперь все работает, как ожидалось, и маркер отображается в центре карты.
Но когда я добавить дополнительный TextView
(см ниже точки зрения с идентификатором edit_location_input
) ниже AutoCompleteTextView
как это:
<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>
маркер показан не в центре карты (на самом деле мне нужно для увеличения и перемещения карты, чтобы увидеть маркер). Похоже, он находится неподалеку.
Когда я установил фиксированную ширину в TextView
<TextView
android:id="@+id/edit_location_result"
android:layout_width="match_parent"
android:layout_height="40dp"/>
маркер появляется в центре, как и ожидалось.
Почему некоторые взгляды влияют на карту и как ее исправить?