我正在尝试在Google Map
标记之上实现布局,因为我有一个带按钮的自定义信息窗口,但按钮仅适用于最后一个标记,因此我尝试在标记顶部修复布局:
public class MainActivity extends FragmentActivity implements InfoWindowAdapter {
static int Tab_Button_Of_List_And_Map_Is_Checked = 0,
Setting_Button_Is_Clicked = 0, Marker_Number, Count_Of_Character,
By_Proximity_And_By_Status_Is_Checked;
int k;
// static MAdapter Adapter;
static GoogleMap Google_Map;
public static ViewGroup Pop_Up;
View pop_1;
public static Marker Marker;
public static double[] latitude2, longitude2;
public static String Map_Current_city = "Lahore", Marker_title,
String_Container_Of_Search_Text = "^";
public static TextView[] UnitsTitle, Units;
public static String[] Cities;
LatLng[] newyorker = {};
public static SupportMapFragment supportMapFragment;
public static ViewSwitcher View_Switcher;
public static Button Back_Button, Map_Button, Refresh_Button, List_Button,
By_Proximity_Button, By_Status_Button, Setting_Button, Mud_Button,
Details_Button;
public static TextView Marker_Title;
public static ArrayList<HashMap<String, String>> Array_Sort_Array_List,
BY_STATUS_Array_List, BY_PROXIMITY_Array_List;
public static ListView List_View;
static OnInfoWindowElemTouchListener Info_Button_Listener;
static Context ctx;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// / Layout Initialization ////////////////////////////////////
Pop_Up = (ViewGroup) this.getLayoutInflater().inflate(
R.layout.contentwidow, null);
// ///////// End Of Layout Initialization//////////////////////
latitude2 = new double[] { 24.983, 25.983, 26.983, 27.983, 28.983,
29.983, 30.983, 31.983, 32.983, 33.983 };
longitude2 = new double[] { 67.028, 68.028, 69.983, 71.983, 72.983,
73.983, 74.983, 75.983, 76.983, 77.983 };
// //// putting the textviews id for unit in array /// //
TextView First_First_Title = (TextView) Pop_Up
.findViewById(R.id.First_first_layout_text_1);
TextView First_Second_Title = (TextView) Pop_Up
.findViewById(R.id.First_Second_layout_text_1);
TextView First_Third_Title = (TextView) Pop_Up
.findViewById(R.id.First_Third_layout_text_1);
TextView First_Fourth_Title = (TextView) Pop_Up
.findViewById(R.id.First_Fourth_layout_text_1);
TextView Second_First_Title = (TextView) Pop_Up
.findViewById(R.id.Second_first_element_text_1);
TextView Second_Second_Title = (TextView) Pop_Up
.findViewById(R.id.Second_second_element_text_1);
TextView Second_Third_Title = (TextView) Pop_Up
.findViewById(R.id.Second_third_element_text_1);
TextView Second_Fourth_Title = (TextView) Pop_Up
.findViewById(R.id.Second_fourth_text_1);
TextView Third_First_Title = (TextView) Pop_Up
.findViewById(R.id.Third_first_element_text_1);
TextView Third_Second_Title = (TextView) Pop_Up
.findViewById(R.id.Third_second_element_text_1);
TextView Third_Third_Title = (TextView) Pop_Up
.findViewById(R.id.Third_third_text_1);
TextView Third_Fourth_Title = (TextView) Pop_Up
.findViewById(R.id.Third_fourth_text_1);
TextView Fourth_First_Title = (TextView) Pop_Up
.findViewById(R.id.Fourth_first_text_1);
TextView Fourth_Second_Title = (TextView) Pop_Up
.findViewById(R.id.fourth_second_text_1);
TextView Fourth_Third_Title = (TextView) Pop_Up
.findViewById(R.id.Fourth_Third_Text_1);
TextView Fourth_Fourth_Title = (TextView) Pop_Up
.findViewById(R.id.Fourth_fourth_text_1);
Units = new TextView[] { First_First_Title, First_Second_Title,
First_Third_Title, First_Fourth_Title, Second_First_Title,
Second_Second_Title, Second_Third_Title, Second_Fourth_Title,
Third_First_Title, Third_Second_Title, Third_Third_Title,
Third_Fourth_Title, Fourth_First_Title, Fourth_Second_Title,
Fourth_Third_Title, Fourth_Fourth_Title };
Cities = new String[] { "Hyderabad", "Karachi", "Islamabad",
"Faisalabad", "Multan", "RawalPindi", "NawabShah", "Sukkur",
"Sanghar", "Lahore" };
// ////// putting the title of units in array //////// //
TextView First_First_Unit = (TextView) Pop_Up
.findViewById(R.id.First_first_Layout_text_2);
TextView First_Second_Unit = (TextView) Pop_Up
.findViewById(R.id.First_Second_layout_text_2);
TextView First_Third_Unit = (TextView) Pop_Up
.findViewById(R.id.First_Third_layout_text_2);
TextView First_Fourth_Unit = (TextView) Pop_Up
.findViewById(R.id.First_fourth_layout_text_2);
TextView Second_First_Unit = (TextView) Pop_Up
.findViewById(R.id.Second_first_element_text_2);
TextView Second_Second_Unit = (TextView) Pop_Up
.findViewById(R.id.Second_second_text_2);
TextView Second_Third_Unit = (TextView) Pop_Up
.findViewById(R.id.Second_third_element_text_2);
TextView Second_Fourth_Unit = (TextView) Pop_Up
.findViewById(R.id.Second_fourth_text_2);
TextView Third_First_Unit = (TextView) Pop_Up
.findViewById(R.id.Third_first_element_text_2);
TextView Third_Second_Unit = (TextView) Pop_Up
.findViewById(R.id.Third_second_element_text_2);
TextView Third_Third_Unit = (TextView) Pop_Up
.findViewById(R.id.Third_third_text_2);
TextView Third_Fourth_Unit = (TextView) Pop_Up
.findViewById(R.id.Third_fourth_text_2);
TextView Fourth_First_Unit = (TextView) Pop_Up
.findViewById(R.id.Fourth_First_text_2);
TextView Fourth_Second_Unit = (TextView) Pop_Up
.findViewById(R.id.Fourth_second_text_2);
TextView Fourth_Third_Unit = (TextView) Pop_Up
.findViewById(R.id.Fourth_third_text_2);
TextView Fourth_Fourth_Unit = (TextView) Pop_Up
.findViewById(R.id.Fourth_fourth_text_2);
UnitsTitle = new TextView[] { First_First_Unit, First_Second_Unit,
First_Third_Unit, First_Fourth_Unit, Second_First_Unit,
Second_Second_Unit, Second_Third_Unit, Second_Fourth_Unit,
Third_First_Unit, Third_Second_Unit, Third_Third_Unit,
Third_Fourth_Unit, Fourth_First_Unit, Fourth_Second_Unit,
Fourth_Third_Unit, Fourth_Fourth_Unit };
supportMapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
for (Marker_Number = 0; Marker_Number < 10; Marker_Number++) {
LatLng NewYorker = new LatLng(latitude2[Marker_Number],
longitude2[Marker_Number]);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
Google_Map = mapFragment.getMap();
Marker = Google_Map.addMarker(new MarkerOptions().position(
NewYorker).title(Cities[Marker_Number]));
Google_Map.moveCamera(CameraUpdateFactory.newLatLngZoom(NewYorker,
15));
// Google_Map.setInfoWindowAdapter(this);
}
Google_Map.setOnMarkerClickListener(new OnMarkerClickListener() {
int a = 0;
@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
LinearLayout linear = (LinearLayout) findViewById(R.id.ll1);
ViewGroup view = (ViewGroup) getLayoutInflater().inflate(R.layout.contentwidow,
linear, false);
if (a == 0) {
a=1;
Log.d("chal", "gaya");
linear.addView(view, 0);
Log.d("hello", "world");
linear.bringToFront();
}
else if(a==1) {
Log.d("1111","222");
linear.removeViewAt(0);
a=0;
}
return true;
}
});
}
@Override
public View getInfoContents(Marker arg0) {
return null;
}
@Override
public View getInfoWindow(final Marker arg0) {
Pop_Up = (ViewGroup) this.getLayoutInflater().inflate(
R.layout.contentwidow, null);
Mud_Button = (Button) Pop_Up.findViewById(R.id.mud_log_button);
MainActivity.Mud_Button
.setOnTouchListener(MainActivity.Info_Button_Listener);
MainActivity.Info_Button_Listener = new OnInfoWindowElemTouchListener(
Mud_Button, null, null) {
@Override
protected void onClickConfirmed(View v) {
// if (Setting_Button_Is_Clicked == 0) {
Log.d("Setting", "Buttonclicked");
Toast.makeText(MainActivity.this,
"setting button" + Marker_Number, Toast.LENGTH_SHORT)
.show();
}
};
// /////// Starting of Setting button //////////// //
return Pop_Up;
}
// /////////// ENDING OF THE UNIMPLEMENTED METHOPD OF INFO WINDOW ADAPTER
// //////
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
boolean ret = false;
int bottomOffsetPixels = 0;
// Make sure that the infoWindow is shown and we have all the needed
// references
if (Marker != null && Marker.isInfoWindowShown() && Google_Map != null
&& Pop_Up != null) {
// Get a marker position on the screen
Point point = Google_Map.getProjection().toScreenLocation(
Marker.getPosition());
// Make a copy of the MotionEvent and adjust it's location
// so it is relative to the infoWindow left top corner
MotionEvent copyEv = MotionEvent.obtain(ev);
copyEv.offsetLocation(-point.x + (Pop_Up.getWidth() / 2), -point.y
+ Pop_Up.getHeight() + bottomOffsetPixels);
// Dispatch the adjusted MotionEvent to the infoWindow
ret = Pop_Up.dispatchTouchEvent(copyEv);
}
// If the infoWindow consumed the touch event, then just return true.
// Otherwise pass this event to the super class and return it's result
return ret || super.dispatchTouchEvent(ev);
}
}
答案 0 :(得分:0)
其实你这样做的方式不对.. 请使用google map api的这种方法来捕获标记事件而不是dispatchEvent()方法,然后它将起作用: -
googlemap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
}
});