Display Map v2 in popup Window not display in android?(在弹出窗口中显示地图 v2 不在 android 中显示?)
问题描述
我想打开弹出窗口,我使用地图 v2 在弹出窗口中显示地图 v2 但未显示这里我放了我的 xml 布局和活动类
<块引用>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"工具:context=".MainActivity" ><按钮android:id="@+id/按钮"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:layout_marginTop="100dp"android:text="按钮"/></相对布局>
<块引用>
popupstellodetailpage.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/popupplayout"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/black"android:orientation="垂直"><按钮android:id="@+id/按钮取消"android:layout_width="wrap_content"android:layout_height="wrap_content"安卓:文本=取消"机器人:layout_gravity="对"/><片段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"/></线性布局>
<块引用>
MapActivity.java
公共类 MainActivity 扩展 FragmentActivity {弹出窗口密码;谷歌地图;@覆盖protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);设置内容视图(R.layout.main);按钮按钮= (Button)findViewById(R.id.button);button.setOnClickListener(new OnClickListener() {@覆盖公共无效 onClick(查看 v){启动弹出窗口();}});}私人无效initialPopupWindow(){尝试{//我们需要获取LayoutInflater的实例,使用这个activity的上下文LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);//从预定义的 XML 布局膨胀视图查看布局 = inflater.inflate(R.layout.popupstellodetailpage,(ViewGroup) findViewById(R.id.popuplayout));//创建一个 300px 宽和 470px 高的 PopupWindowpw = new PopupWindow(布局, 300, 470, true);//在中间显示弹窗pw.showAtLocation(布局, Gravity.CENTER, 0, 0);地图=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.popupmapview)).getMap();按钮 buttoncancel=(Button)layout.findViewById(R.id.buttoncancel);buttoncancel.setOnClickListener(new OnClickListener(){@覆盖public void onClick(查看 v){pw.dismiss();}});}捕获(异常 e){e.printStackTrace();}}}
他们只是我发现的两个愚蠢的问题..你只需改变这个片段
<片段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"/>
到这个..
<片段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"/>
并在方法 [initiatePopupWindow] 中更改一行
map= ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.popupmapview)).getMap();
到这个..
map = ((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 不在 android 中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在弹出窗口中显示地图 v2 不在 android 中显示?
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01