0
經過相當多的努力之後,我設法在我的MapFragment中放置了自動填充功能。仍然有一個問題。在MapFragment中放置自動完成功能:在舊API上不可見
在我的Android模擬器(API 24),它是可見的,我可以用它:
在我的智能手機(API 19)我還看不出來,除了一小瞬間只在地圖加載之前。
我map_layout.xml是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="top"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="40dp"
card_view:cardCornerRadius="4dp">
</android.support.v7.widget.CardView>
</RelativeLayout>
的MapFragment.java裏面的代碼是這一個:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialise a new fragment inside of this one.
mFragmentManager = getChildFragmentManager();
mSupportMapFragment = (SupportMapFragment) mFragmentManager.findFragmentByTag("mapFragment");
mSupportPlaceAutocompleteFragment = (SupportPlaceAutocompleteFragment) mFragmentManager.findFragmentByTag("autocompleteFragment");
// Never inflate fragments inside other fragments in a layout.xml!
// Do it programmatically.
// See here for reference: http://stackoverflow.com/a/19815266/4938112.
if (mSupportMapFragment == null) {
mSupportMapFragment = new SupportMapFragment();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.add(R.id.map_fragment_container, mSupportMapFragment, "mapFragment");
mFragmentTransaction.commit();
mFragmentManager.executePendingTransactions();
}
// Asynchronous thread to load map.
mSupportMapFragment.getMapAsync(this);
if (mSupportPlaceAutocompleteFragment == null) {
mSupportPlaceAutocompleteFragment = new SupportPlaceAutocompleteFragment();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.add(R.id.card_view, mSupportPlaceAutocompleteFragment, "autocompleteFragment");
mFragmentTransaction.commit();
mFragmentManager.executePendingTransactions();
}
}
我已經發現如果我只是將地址自動填充直接附加到map_fragment_container,即使在我的智能手機上,我也能看到它,但它有一個看不見的背景。
任何提示?