Popup window 无法在 Marker 上运行
The Popup window cannot function on Marker
早上好
在这里,我尝试在标记点击时添加弹出 window 功能,但是当我启动我的应用程序时,弹出窗口不起作用。
我也在尝试解决,还是无法解决问题
这是我的java代码
package com.everstudio.nadejenew;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
public class LocationFragment extends Fragment implements OnMapReadyCallback {
static View view;
private GoogleMap mMap;
private RelativeLayout dialog_popup;
Marker m1;
public LocationFragment() {
// Required empty public constructor
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (view == null) {
view = inflater.inflate(R.layout.fragment_location, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
return view;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Add a marker in Sydney and move the camera
LatLng location = new LatLng(2.1895696, 102.2478482);
m1 = mMap.addMarker(new MarkerOptions().position(location).title("Location"));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(Marker Marker) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.marker_popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismissbtn);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
return true;
}
});
}
}
你不见了popupWindow.showAsDropDown(popupView);
早上好
在这里,我尝试在标记点击时添加弹出 window 功能,但是当我启动我的应用程序时,弹出窗口不起作用。 我也在尝试解决,还是无法解决问题
这是我的java代码
package com.everstudio.nadejenew;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
public class LocationFragment extends Fragment implements OnMapReadyCallback {
static View view;
private GoogleMap mMap;
private RelativeLayout dialog_popup;
Marker m1;
public LocationFragment() {
// Required empty public constructor
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (view == null) {
view = inflater.inflate(R.layout.fragment_location, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
return view;
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Add a marker in Sydney and move the camera
LatLng location = new LatLng(2.1895696, 102.2478482);
m1 = mMap.addMarker(new MarkerOptions().position(location).title("Location"));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(Marker Marker) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.marker_popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismissbtn);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
return true;
}
});
}
}
你不见了popupWindow.showAsDropDown(popupView);