如何使用MapView制作2个分屏?

时间:2010-01-06 11:27:26

标签: android google-maps

我正在尝试使用Google Map制作屏幕。

此屏幕有两个部分。第一部分包括Button TextView和ListView,位于Screen的顶部。第二部分包括MapView(谷歌地图)和屏幕底部的位置。

如何制作?

我做到了。但没有运气。它抛出了这个例外:

01-07 11:53:12.813: ERROR/AndroidRuntime(725): Uncaught handler: thread main exiting due to uncaught exception
01-07 11:53:12.833: ERROR/AndroidRuntime(725): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackagename.uk/com.mypackagename.uk.MyCustomActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class java.lang.reflect.Constructor
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.os.Looper.loop(Looper.java:123)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.main(ActivityThread.java:3948)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at java.lang.reflect.Method.invokeNative(Native Method)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at java.lang.reflect.Method.invoke(Method.java:521)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at dalvik.system.NativeStart.main(Native Method)
01-07 11:53:12.833: ERROR/AndroidRuntime(725): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class java.lang.reflect.Constructor
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.createView(LayoutInflater.java:512)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:564)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.parseInclude(LayoutInflater.java:701)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:613)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.Activity.setContentView(Activity.java:1626)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.mypackagename.uk.MyCustomActivity.onCreate(*MyCustomActivity.java:457*)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     ... 11 more
01-07 11:53:12.833: ERROR/AndroidRuntime(725): Caused by: java.lang.reflect.InvocationTargetException
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.google.android.maps.MapView.<init>(MapView.java:237)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at android.view.LayoutInflater.createView(LayoutInflater.java:499)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     ... 23 more
01-07 11:53:12.833: ERROR/AndroidRuntime(725): Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:180)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.google.android.maps.MapView.<init>(MapView.java:279)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     at com.google.android.maps.MapView.<init>(MapView.java:254)
01-07 11:53:12.833: ERROR/AndroidRuntime(725):     ... 27 more

我有抛出异常的代码行:MyCustomActivity.java:457

这一行是:setContentView(R.layout.my_layout);

我的XML是:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_vertical">
<com.mypackagename.uk.MyLayout
<TableLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
    <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/my_row1">
        <TableLayout android:layout_width="fill_parent" 
            android:layout_height="wrap_content" android:layout_weight="1">     
            <TableRow android:layout_marginTop="5dip" android:layout_height="wrap_content" android:layout_width="fill_parent">
                <TextView android:layout_height="wrap_content"></TextView>
                <ImageView android:layout_width="wrap_content"></ImageView>
                <TextView android:layout_width="wrap_content"></TextView>
                <TextView android:layout_height="wrap_content" android:layout_width="15px"></TextView>
                <ImageView android:layout_height="wrap_content"></ImageView>
            </TableRow>
        </TableLayout>
    </TableRow>
</TableLayout>
<com.google.android.maps.MapView
    android:id="@+id/map_view_on_yardage"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="my-api-code">
</com.google.android.maps.MapView>
</com.mypackagename.uk.MyLayout>

1 个答案:

答案 0 :(得分:0)

我也有问题..我确实喜欢这个...... 创建一个可以接受两个片段的布局...... .. 在top_fragment上放置你需要的内容...... 并在下面的片段放置地图片段......

我希望它对你有用......

<强> nested_frag.xml

<FrameLayout
    android:id="@+id/top_content"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.7"
    android:background="#fff2ff" >
</FrameLayout>

<FrameLayout
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.3"
    android:background="#fff2ff" >
</FrameLayout>

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.nested_frag, container, false);
    b = getArguments();

    Fragment map = new MapFragment();

    map.setArguments(b);

    FragmentTransaction trans = getChildFragmentManager()
            .beginTransaction();
    trans.add(R.id.top_content, new HomeScreen());
    trans.add(R.id.map, map).addToBackStack("somestack").commit();

    return view;
}