布局Android的问题

时间:2011-04-11 10:33:40

标签: android xml android-layout layout android-mapview

我想在顶部创建一个简单的界面MapView,在底部创建一个Button来刷新MapView。这两个元素都应该在 width fill_parent,但我希望它们在 height 中不重叠。我的问题是我的mapview似乎与我的Button重叠并隐藏了它。这是我的layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" >

     <com.google.android.maps.MapView
          android:id="@+id/mapview"
          android:layout_width="fill_parent"
          android:layout_height="match_parent"
          android:enabled="true"
          android:clickable="true"
          android:apiKey="my_api_key" /> 

     <Button 
          android:id="@+id/close"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_alignParentBottom="true"
          android:text="@string/title_close" /> 
</LinearLayout>

提前致谢。

2 个答案:

答案 0 :(得分:1)

  1. 使用RelativeLayout
  2. 使用layout_alignParentBottom="true"作为第一个孩子放置一个按钮,将其设为layout_width="fill_parent"layout_height="wrap_content"
  3. 将MapView放在layout_above="@id/close"
  4. 的第二位
  5. 设为layout_width="fill_parent"layout_height="fill_parent"

答案 1 :(得分:0)

您必须使用layout_weight调整按钮和地图的大小 使用layout_height =“wrap_content”

更好地按下按钮

尝试使用权重= 0.5的地图和使用2或类似的按钮