0

您好我正在尝试将自定义列表视图放在 mapFragment 的顶部(我使用的是 GoogleMaps api V2)。此 mapFragment 位于 ActionBarTab 的 Fragment 中。我研究了 tileOverlay 和 groundOverlay,但它们都是关于在地图上放置图像(根据我的理解)。有没有办法在 mapFragment 上膨胀 ListView。这是我的片段布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/fragment_regional_analysis" >


        <ListView
            android:id="@android:id/list"
            android:layout_width="300dp"
            android:layout_height="fill_parent"
            android:background="@android:color/transparent"
            android:cacheColorHint="@android:color/transparent" />
        <View 
            android:id="@+id/mapView"                   
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

</LinearLayout>

这是片段类

`

public class RegionalFragment extends Fragment 
  {

static final LatLng UK = new LatLng(53.4167, 3.0000);
static final LatLng LONDON = new LatLng(51.5171, 0.1062);
static final LatLng Brimingham = new LatLng(52.4800, 1.9100);
private MapFragment mapFragment;
private GoogleMap map;
ProgressBar progressBar;
int progress = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_container,
            container, false);
    mapFragment = new MapFragment() {
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            map = mapFragment.getMap();

            if (map != null) {
                 setupMap();
            }
        }
    };
    // fragment added dynamically
    FragmentTransaction transaction = getFragmentManager()
            .beginTransaction();
    transaction.add(R.id.mapView, mapFragment).commit();
    return v;
}`

Logcat 错误:

04-16 09:38:40.300: E/AndroidRuntime(807): FATAL EXCEPTION: main
04-16 09:38:40.300: E/AndroidRuntime(807): java.lang.ClassCastException: android.view.View cannot be        cast to android.view.ViewGroup
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:875)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.app.BackStackRecord.run(BackStackRecord.java:682)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.os.Handler.handleCallback(Handler.java:725)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.os.Looper.loop(Looper.java:137)
04-16 09:38:40.300: E/AndroidRuntime(807):  at android.app.ActivityThread.main(ActivityThread.java:5041)
04-16 09:38:40.300: E/AndroidRuntime(807):  at java.lang.reflect.Method.invokeNative(Native Method)
04-16 09:38:40.300: E/AndroidRuntime(807):  at java.lang.reflect.Method.invoke(Method.java:511)
04-16 09:38:40.300: E/AndroidRuntime(807):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-16 09:38:40.300: E/AndroidRuntime(807):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-16 09:38:40.300: E/AndroidRuntime(807):  at dalvik.system.NativeStart.main(Native Method)

提前致谢。

4

1 回答 1

0

你不能把它放到你的布局文件中吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="AS_YOU_WANT_IT" />

<fragment
    android:id="@+id/mapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>

并在你的片段中膨胀这个?

于 2013-04-16T06:23:30.777 回答