0
我的佈局是這樣的:的Android谷歌地圖的標記不居中
<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
(見下圖與ID 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"/>
標記如預期出現在中心。
爲什麼有些視圖會影響地圖以及如何解決?