显示地图V2在弹出的窗口中机器人不显示? [英] Display Map v2 in popup Window not display in android?

查看:130
本文介绍了显示地图V2在弹出的窗口中机器人不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开弹出窗口,我使用的地图V2在弹出窗口中显示的地图V2,但不显示 在这里,我把我的XML布局和活动类

  

main.xml中

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:以下属性来=@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    工具:上下文=MainActivity。>

    <按钮
        机器人:ID =@ + ID /按钮
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:layout_marginTop =100dp
        机器人:文本=按钮/>

< / RelativeLayout的>
 

  

popupstellodetailpage.xml

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / popuplayout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:背景=@机器人:彩色/黑白
    机器人:方向=垂直>

        <按钮
            机器人:ID =@ + ID / buttoncancel
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=取消
            机器人:layout_gravity =右
             />

          <片段
                    机器人:ID =@ + ID / popupmapview
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =FILL_PARENT
                    机器人:layout_margin =10dp
                    类=com.google.android.gms.maps.SupportMapFragment/>



< / LinearLayout中>
 

  

MapActivity.java

 公共类MainActivity扩展FragmentActivity {


     PopupWindow PW;
     GoogleMap的地图;
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        Button按钮=(按钮)findViewById(R.id.button);
        button.setOnClickListener(新OnClickListener(){

            @覆盖
            公共无效的onClick(视图v){

                initiatePopupWindow();
            }
        });

    }


    私人无效initiatePopupWindow()
    {
        尝试
        {

            //我们需要得到LayoutInflater的情况下,使用此活动的背景下
            LayoutInflater充气=(LayoutInflater)MainActivity.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //充气从predefined XML布局视图
            查看布局= inflater.inflate(R.layout.popupstellodetailpage,
                    (ViewGroup中)findViewById(R.id.popuplayout));

            //创建一个300px的宽度和高度470px PopupWindow
            PW =新PopupWindow(布局,300,470,真);

            //显示在中心的弹出
            pw.showAtLocation(布局,Gravity.CENTER,0,0);


            地图=((SupportMapFragment)getSupportFragmentManager()
                     .findFragmentById(R.id.popupmapview))的GetMap()。


            按钮buttoncancel =(按钮)layout.findViewById(R.id.buttoncancel);
            buttoncancel.setOnClickListener(新OnClickListener()
            {
                @覆盖
                公共无效的onClick(视图v)
                {
                     pw.dismiss();
                }

            });

        }
        赶上(例外五)
        {
            e.printStackTrace();
        }


    }
}
 

解决方案

他们是仅有的两个傻问题,我发现..你只需要改变这个片段

 <片段
                机器人:ID =@ + ID / popupmapview
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =FILL_PARENT
                机器人:layout_margin =10dp
                类=com.google.android.gms.maps.SupportMapFragment/>
 

这个..

 <片段
                机器人:ID =@ + ID / popupmapview
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =FILL_PARENT
                机器人:layout_margin =10dp
                类=com.google.android.gms.maps.MapFragment/>
 

和改变行法[initiatePopupWindow]

地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.popupmapview)。)的GetMap()。

这个..

地图=((MapFragment)getFragmentManager()findFragmentById(R.id.popupmapview)。)的GetMap();

i want to open the popup window on that i used the map v2 for displaying map v2 in popup window but is not display here i put my xml layout and activity class

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="100dp"
        android:text="Button" />

</RelativeLayout>

popupstellodetailpage.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popuplayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:orientation="vertical" >

        <Button
            android:id="@+id/buttoncancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel"
            android:layout_gravity="right"
             />

          <fragment
                    android:id="@+id/popupmapview"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="10dp"
                    class="com.google.android.gms.maps.SupportMapFragment" />



</LinearLayout>

MapActivity.java

public class MainActivity extends  FragmentActivity {


     PopupWindow pw;
     GoogleMap map;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button button= (Button)findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                initiatePopupWindow();
            }
        });

    }


    private void initiatePopupWindow() 
    {
        try 
        {

            //We need to get the instance of the LayoutInflater, use the context of this activity
            LayoutInflater inflater = (LayoutInflater) MainActivity.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //Inflate the view from a predefined XML layout
            View layout = inflater.inflate(R.layout.popupstellodetailpage,
                    (ViewGroup) findViewById(R.id.popuplayout));

            // create a 300px width and 470px height PopupWindow
            pw = new PopupWindow(layout, 300, 470, true);

            // display the popup in the center
            pw.showAtLocation(layout, Gravity.CENTER, 0, 0);


            map= ((SupportMapFragment) getSupportFragmentManager()
                     .findFragmentById(R.id.popupmapview)).getMap(); 


            Button buttoncancel=(Button)layout.findViewById(R.id.buttoncancel);
            buttoncancel.setOnClickListener(new OnClickListener() 
            {   
                @Override
                public void onClick(View v) 
                {
                     pw.dismiss();
                }

            });

        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }


    }
}

解决方案

their is only two silly problem as I found .. You just change this fragment

                <fragment
                android:id="@+id/popupmapview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_margin="10dp"
                class="com.google.android.gms.maps.SupportMapFragment" />

to this..

                <fragment
                android:id="@+id/popupmapview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_margin="10dp"
                class="com.google.android.gms.maps.MapFragment" />

and change a line in method [initiatePopupWindow]

map= ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.popupmapview)).getMap();

to this..

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.popupmapview)).getMap();

这篇关于显示地图V2在弹出的窗口中机器人不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆