0

这是我使用的 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="wrap_content"
android:orientation="vertical" >

<fragment
        android:id="@+id/map"
        android:layout_width="251dp"
        android:layout_height="174dp"
        android:layout_gravity="center"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        class="com.google.android.gms.maps.MapFragment" />

   <ListView
      android:id="@+id/tips"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_marginBottom="20dp"
      android:layout_marginLeft="20dp"
      android:layout_marginRight="20dp"
      android:layout_weight="1.64"
      android:clickable="false"
      android:focusable="false"
      android:focusableInTouchMode="false"
      android:listSelector="@android:color/transparent" >
   </ListView>
 </LinearLayout>

如果我不向 xml 添加片段,它可以正常工作,但是当我将片段添加到布局(如上添加)时它不起作用......有什么问题,请帮助我。

这是清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.googleapi"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />
<permission
    android:name="example.googleapi.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"></permission>
<uses-permission
    android:name="example.googleapi.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>


<application
android:permission="android.permission.WRITE_EXTERNAL_STORAGE"

android:testOnly="false"
android:debuggable="true"
android:allowBackup="true"
    android:icon="@drawable/action_icon"
    android:label="@string/app_name"
    android:theme="@style/AppBaseTheme">

   <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="My API KEY"/> 

     <activity
        android:name="example.googleapi.Main_Activity_List"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

 </application>

 </manifest>
4

3 回答 3

0

就我而言,我这样声明地图

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

    <com.google.android.gms.maps.MapView
        android:id="@+id/rote_search_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    </com.google.android.gms.maps.MapView>
...
...
...
</FrameLayout>
于 2013-11-05T15:11:41.593 回答
0

您需要再添加一项权限

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

在您的 MainActivity 中,您应该扩展 FragmentActivity

public class MainActivity extends android.support.v4.app.FragmentActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.Your_XML);
   }
}

我希望这可以帮助你。

于 2013-11-05T14:54:09.357 回答
0
// try this
**activity_main.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="wrap_content"
    android:orientation="vertical" >

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

    <ListView
        android:id="@+id/tips"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_weight="0.60"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:listSelector="@android:color/transparent"/>
</LinearLayout>

public class MainActivity extends FragmentActivity {

    GoogleMap googleMap;
    ListView tips;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tips=(ListView)findViewById(R.id.tips);
        FragmentManager fm = getSupportFragmentManager();
        SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.maps);
        googleMap = f.getExtendedMap();
    }
}
于 2013-11-06T10:42:49.240 回答