【发布时间】:2014-04-03 19:52:25
【问题描述】:
我是安卓新手。我正在做一个项目作为我学术的一部分。我想在谷歌地图的底部有几个按钮,就像在 waze android 应用程序中一样(抱歉,无法发布屏幕截图)。我根据以下链接尝试了几件事 How to add buttons at top of map fragment API v2 layout 。但没有得到想要的结果。
有人可以帮我设计正确的布局吗?感谢您的帮助。
【问题讨论】:
标签: map
我是安卓新手。我正在做一个项目作为我学术的一部分。我想在谷歌地图的底部有几个按钮,就像在 waze android 应用程序中一样(抱歉,无法发布屏幕截图)。我根据以下链接尝试了几件事 How to add buttons at top of map fragment API v2 layout 。但没有得到想要的结果。
有人可以帮我设计正确的布局吗?感谢您的帮助。
【问题讨论】:
标签: map
试试这个:
<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"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
<Button
android:id="@+id/setRangeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setRange" />
</RelativeLayout>
【讨论】:
您可以扩展 SupportMapFragment 并覆盖 OnCreateView 以编程方式进行::
public class myMap extends SupportMapFragment{
private Context context;
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = super.onCreateView(inflater, container,savedInstanceState);
//save context
this.context = v.getContext();
RelativeLayout view = new RelativeLayout(v.getContext());
//add relative layout
view.addView(v, new RelativeLayout.LayoutParams(-1, -1));
TextView stuff = new EditText(v.getContext());
stuff.setText("Hey you, I was added programatically!");
view.addView(stuff);
initializeMap();
return view; //return
}
private initializeMap(){
//add things to the map here
getMap().addMarker(new MarkerOptions().add(new LatLng(-37.81319, 144.96298)));
}
}
【讨论】:
使用此代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button 1"/>
</RelativeLayout>
【讨论】: