Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在活动中插入SupportMapFragment?_Android_Google Maps_Android Fragments_Supportmapfragment - Fatal编程技术网

Android 如何在活动中插入SupportMapFragment?

Android 如何在活动中插入SupportMapFragment?,android,google-maps,android-fragments,supportmapfragment,Android,Google Maps,Android Fragments,Supportmapfragment,我已经用AndroidStudio为地图创建了自动活动 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:name="com.google.android.

我已经用AndroidStudio为地图创建了自动活动

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.mitic.mappa.MapsActivity"
    android:id="@+id/contenitore"
    android:background="#ccebff">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#3365ff"
        android:id="@+id/navBar">

        <Button
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="Dove vuoi andare?"
            android:layout_weight="1"
            android:textColor="@color/common_signin_btn_dark_text_default"
            android:id="@+id/b1"
            android:textStyle="bold"
            android:background="#3365ff"
            android:onClick="scegliPercorso"
            android:layout_marginBottom="10dp"/>

        <Button
            android:textColor="@color/common_signin_btn_dark_text_default"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="Mappa generale"
            android:id="@+id/b2"
            android:layout_weight="1"
            android:textStyle="bold"
            android:onClick="visualizzaMappaGenerale"
            android:background="#3365ff" />

        <Button
            android:textColor="@color/common_signin_btn_dark_text_default"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="Informazioni UnisaMapp"
            android:layout_toRightOf="@id/b2"
            android:layout_weight="1"
            android:textStyle="bold"
            android:onClick="info"
            android:background="#3365ff" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/navBar"
        android:id="@+id/layout2">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="#ffffff"
            android:id="@+id/contFragment">

        </LinearLayout>
    </RelativeLayout>

    <fragment
        android:layout_below="@id/layout2"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</RelativeLayout>
我想在活动中添加这个片段,所以我创建了这个类

public class Appoggio extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_layout);
    }
}
这是map_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".Appoggio"
    android:background="#ccebff">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/containers">
    </RelativeLayout

</RelativeLayout>


在主活动中放置一个视图寻呼机,然后将片段添加到视图寻呼机中

ViewPager pager= (ViewPager) findViewById(R.id.pager);
 TabsPagerfragment tabsPagerfragment=new TabsPagerfragment(getSupportFragmentManager());

        pager.setAdapter(tabsPagerAdapter);

希望这对你有帮助

在主要活动中放置一个视图寻呼机,然后将片段添加到视图寻呼机中

ViewPager pager= (ViewPager) findViewById(R.id.pager);
 TabsPagerfragment tabsPagerfragment=new TabsPagerfragment(getSupportFragmentManager());

        pager.setAdapter(tabsPagerAdapter);
希望这对你有帮助