+ -
当前位置:首页 → 问答吧 → (紧急求救)关於android google map 既java问题(marker snippet)

(紧急求救)关於android google map 既java问题(marker snippet)

时间:2014-01-10

来源:互联网

想问下如果用marker 既snippet去打一d资料
好似
final LatLng place = new LatLng(100,-100);<----呢个我系随便打
Marker place1 = mMap.addMarker(new MarkerOptions()
.position(place)
.title("A restaurant")
.snippet("Open time"));
我想出黎既野如果系
Open time
Mon - Fri 9am - 11pm
Sat 12am - 6pm
Sun close
咁可以点打
因为试过
.snippet("Open time")
.snippet("Mon - Fri 9am - 11pm")
.snippet(" Sat 12am - 6pm")
.snippet(" Sun close")
佢显示就剩系得个Sun close
如果.snippet("Open time"+"Mon - Fri 9am - 11pm"+" Sat 12am - 6pm"+" Sun close")
又会变做Open time Mon - Fri 9am - 11pm Sat 12am - 6pm Sun close
点可以令佢隔行或者定系唔同snippet而用其他command??

[ 本帖最后由 petroscheung 於 2013-12-5 09:34 AM 编辑 ]

作者: petroscheung   发布时间: 2014-01-10

佢本身title及snippet都只容许一行.
如果想改变佢预设方式,要自订info window adapter.

e.g. 假设你用番你现时activity或fragment做你个adapter及预备一个layout file.
...
map.setInfoWindowAdapter(this);
...

LAYOUT FILE: map_info.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
androidrientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="2dip"
android:src="@drawable/ic_launcher"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
androidrientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

你个activity/fragment 要implements InfoWindowAdapter, 会有两个method
@Override
public View getInfoContents(Marker marker) {
View v = this.getLayoutInflater(null).inflate(R.layout.map_info_window , null);
// set 番D title 及 snippet
TextView txtTitle = (TextView) v.findViewById( R.id.title );
tvTitle.setText( marker.getTitle() );
TextView txtSnippet = (TextView) v.findViewById( R.id.snippet );
tvSnippet.setText( marker.getSnippet() );
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
用左 textview, 你可以用 \n 做每行分隔,e.g.
marker.setTitle("Title 1\nTitle 2\nTitle 3");
marker.setSnippet("line 1\nline2\nline3");

既然infowindow用左layout file,玩唛花款随你喜欢.



[ 本帖最后由 laputafish 於 2013-12-7 03:35 PM 编辑 ]

作者: laputafish   发布时间: 2014-01-10

热门下载

更多