0

我想在 Activity 中显示 GoogleMap,就像这样,红色矩形是地图,绿色矩形是已经存在的其他布局。

我已经有一个具有地图功能的 MapFragment,所以令牌和其他东西都可以。我试图插入这个片段

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

到活动的XML布局文件(活动是一个FragmentActivity,每个组件都放在一个FrameLayout内),但是在膨胀布局时它给了我错误。

我该如何解决这个问题?

4

1 回答 1

0
// try this and modify as per your requirement
 **XML**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/lnrAddressSearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:padding="3dp" >

        <EditText
            android:id="@+id/editSearch"
            style="?edittext_h3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:singleLine="true" />

        <ImageView
            android:id="@+id/imgSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:adjustViewBounds="true"
            android:padding="2dp"
            android:scaleType="fitXY"
            android:src="@drawable/ijoomer_search_icon" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <fragment
            android:id="@+id/maps"
            android:name="pl.mg6.android.maps.extensions.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lnrLstMapAddress"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:orientation="vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/txtMapAddressHints"
                style="?textview_h2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:padding="5dp"
                android:text="Tap On Map To Get Address" />

            <ListView
                android:id="@+id/lstMapAddress"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:cacheColorHint="#00000000"
                android:divider="@color/blue"
                android:dividerHeight="1dp"
                android:smoothScrollbar="true"
                android:visibility="gone" />

            <ProgressBar
                android:id="@+id/pbrLstMapAddress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:visibility="gone" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

 **Activity**
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xml);
          FragmentManager fm = getSupportFragmentManager();
            SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.maps);
        googleMap = f.getExtendedMap();

        lstMapAddress = (ListView) findViewById(R.id.lstMapAddress);
        pbrLstMapAddress = (ProgressBar) findViewById(R.id.pbrLstMapAddress);
        txtMapAddressHints = (TextView) findViewById(R.id.txtMapAddressHints);
        editSearch = (EditText) findViewById(R.id.editSearch);
        imgSearch = (ImageView) findViewById(R.id.imgSearch);

        googleMap.setMyLocationEnabled(true);
        googleMap.setOnMapClickListener(this);
    }
于 2013-09-13T13:51:25.517 回答