在Activity中的其他布局之间显示MapFragment

时间:2013-09-13 13:42:20

标签: android google-maps android-fragments

我想在活动中显示Google地图,例如this,其中红色矩形是地图,绿色是其他布局已经存在。

我已经有一个MapFragment,它有一个map功能,所以令牌和其他东西都没问题。我试图插入这个片段

 <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中),但它在给布局膨胀时给出了错误。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分: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);
    }