我正在做一个必须显示标题和说明的项目。但问题是描述中的文字有点冗长,当我们点击标记时没有显示。我想要显示完整描述的片段大小,否则需要一些其他选项?
@SuppressLint("NewApi") public class GoogleActivity extends
FragmentActivity implements LocationListener {
private LocationManager locationManager; private static final long
MIN_TIME = 700; private static final float MIN_DISTANCE = 800;
// Google Map private GoogleMap googleMap; LatLng myPosition;
// All static variables static final String URL =
"http://webersspot.accountsupport.com/gmaptrial/onedb/phpsqlajax_genxml.php";
// XML node keys
static final String KEY_PID = "pro"; // parent node static final
String KEY_NAME = "Name"; static final String KEY_DESCRIPTION =
"Description"; static final String KEY_LAT = "Latitude"; static
final String KEY_LONG = "Longitude";
ArrayList<HashMap<String, String storeMapData = new
ArrayList<HashMap<String, String (); private ShareActionProvider
mShareActionProvider;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); // Hybrid for
satellite with place name
googleMap.setMyLocationEnabled(true); // enable user location
button. googleMap.setInfoWindowAdapter(null) ;
googleMap.getUiSettings().setZoomControlsEnabled(true);
googleMap.getUiSettings().setCompassEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
googleMap.getUiSettings().setAllGesturesEnabled(true);
googleMap.setTrafficEnabled(true); // enable road
/*
// Get Location Manager and check for GPS & Network location
services
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
// Build the alert dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Location Services Not Active");
builder.setMessage("Please enable Location Services and GPS");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
// Show location settings when the user acknowledges the alert dialog
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
Dialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
} */
new LongOperation().execute(""); new
MapOperation().execute(googleMap);
locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
MIN_TIME, MIN_DISTANCE, this); //You can also use
LocationManager.GPS_PROVIDER and LocationManager.PASSIVE_PROVIDER
}
public List<HashMap<String, String prepareData(){
ArrayList<HashMap<String, String menuItems = new
ArrayList<HashMap<String, String (); //List<HashMap<String,
String menuItems = new ArrayList<HashMap<String, String ();
XmlParser parser = new XmlParser(); String xml =
parser.getXmlFromUrl(URL); // getting XML Document doc =
parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_PID); // looping
through all item nodes <item for (int i = 0; i < nl.getLength();
i++) { // creating new HashMap HashMap<String, String map = new
HashMap<String, String (); Element e = (Element) nl.item(i);
System.out.println("OOOOOOOOOOOOOOOOOOO :::
"+e.getAttribute(KEY_NAME)); // adding each child node to HashMap
key = value
map.put(KEY_NAME, e.getAttribute(KEY_NAME).toString());
map.put(KEY_DESCRIPTION
,e.getAttribute(KEY_DESCRIPTION).toString()); map.put(KEY_LAT,
e.getAttribute(KEY_LAT).toString()); map.put(KEY_LONG
,e.getAttribute(KEY_LONG).toString());
// adding HashList to ArrayList menuItems.add(map);
storeMapData = menuItems;
} return menuItems;
}
public void onMapReady(final GoogleMap map) {
ArrayList<HashMap<String, String processData = storeMapData;
System.out.println( "kjkasdc "+processData);
for (int i=0; i< processData.size(); i++){
final double lat =
Double.parseDouble(processData.get(i).get(KEY_LAT));
System.out.println("MAP LAT ::::::::::::::::::::::::: "+lat);
final double lon =
Double.parseDouble(processData.get(i).get(KEY_LONG));
System.out.println("MAP LON ::::::::::::::::::::::::: "+lon);
final String address = processData.get(i).get(KEY_DESCRIPTION);
System.out.println("MAP ADDRESS :::::::::::::::::::::::::
"+address); final String name = processData.get(i).get(KEY_NAME);
System.out.println("MAP ADDRESS ::::::::::::::::::::::::: "+name);
runOnUiThread(new Runnable() {
@Override
public void run() {
final LatLng MELBOURNE = new LatLng(lat, lon);
Marker melbourne = map.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title(name)
.snippet(address)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));
melbourne.showInfoWindow();
// map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title(name).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));
} });
} }
@SuppressLint("NewApi") @Override public boolean
onCreateOptionsMenu(Menu menu) {
/** Inflating the current activity's menu with res/menu/items.xml */
getMenuInflater().inflate(R.menu.share_menu, menu);
mShareActionProvider = (ShareActionProvider)
menu.findItem(R.id.menu_item_share).getActionProvider();
/** Setting a share intent */
mShareActionProvider.setShareIntent(getDefaultShareIntent());
return super.onCreateOptionsMenu(menu);
}
/** Returns a share intent */ private Intent
getDefaultShareIntent(){ Intent intent = new
Intent(Intent.ACTION_SEND); intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT,"Download");
intent.putExtra(Intent.EXTRA_TEXT,"Download Hill Top Beauty Parlour
App - Maroli from Google Play Store:
https://play.google.com/store/apps/details?id=beauty.parlour.maroli");
return intent; }
private class LongOperation extends AsyncTask<String, Void, String {
@Override protected String doInBackground(String... params) {
prepareData(); return "Executed"; } @Override protected void onPostExecute(String result) {
System.out.println("Executed"); } @Override protected void
onPreExecute() { System.out.println("Execution started");
} @Override protected void onProgressUpdate(Void... values) {
System.out.println(" -- -- -- "+values); } }
private class MapOperation extends AsyncTask<GoogleMap, Void, String
{ @Override protected String doInBackground(GoogleMap... params) {
GoogleMap map = params[0]; onMapReady(map); return
"Executed"; } @Override protected void onPostExecute(String
result) { System.out.println(result); } @Override
protected void onPreExecute() {
System.out.println("Execution started"); } @Override
protected void onProgressUpdate(Void... values) {
System.out.println(" -- -- -- "+values); } }
class MyInfoWindowAdapter implements InfoWindowAdapter{
private final View myContentsView;
MyInfoWindowAdapter(){ myContentsView =
getLayoutInflater().inflate(R.layout.custom_info_contents, null); }
@Override public View getInfoContents(Marker marker) {
TextView tvTitle =
((TextView)myContentsView.findViewById(R.id.title));
tvTitle.setText(marker.getTitle()); TextView tvSnippet =
((TextView)myContentsView.findViewById(R.id.snippet));
tvSnippet.setText(marker.getSnippet());
return myContentsView; }
@Override public View getInfoWindow(Marker marker) { // TODO
Auto-generated method stub return null;
}
}
@Override public void onLocationChanged(Location location) { //
TODO Auto-generated method stub LatLng latLng = new
LatLng(location.getLatitude(), location.getLongitude());
CameraUpdate cameraUpdate =
CameraUpdateFactory.newLatLngZoom(latLng, 10);
googleMap.animateCamera(cameraUpdate);
locationManager.removeUpdates(this);
}
@Override public void onStatusChanged(String provider, int status,
Bundle extras) { // TODO Auto-generated method stub
}
@Override public void onProviderEnabled(String provider) { // TODO
Auto-generated method stub
}
@Override public void onProviderDisabled(String provider) { //
TODO Auto-generated method stub
}
}
<?xml version="1.0" encoding="utf-8"?>
<Relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="300dp"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/snippet"
android:marqueeRepeatLimit="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp" />
</Relativelayout>
答案 0 :(得分:0)
您可以添加自定义弹出窗口而不是片段,类似这样,
private void showPopup(final Activity context, String address) {
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.pop_up_layout, viewGroup);
TextView textView = (TextView) layout.findViewById(R.id.txt_address);
textView.setText(address);
// Creating the PopupWindow
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
popup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
popup.setFocusable(true);
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, mPoint.x, mPoint.y + 50 );
}
用于演示安装并检查here