2012-07-22 70 views
0

我厌倦了试图解决这个问题,但没有运气。MapView正在布局整个空间

我有布局组成的地图视图,搜索栏和EditText。

问题mapview正在占用整个空间,所以EditText文本没有出现。

我试图玩重量值,但没有运气。

感谢您的帮助。

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

    a:layout_height="fill_parent" > 


     <com.google.android.maps.MapView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/mapview" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:apiKey="somekey" 
      android:clickable="true" 

      android:layout_weight="0" 
      a:layout_alignParentTop="true" 
      /> 

     <SeekBar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/seekBar1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 

      android:layout_marginTop="26dp" 
      a:paddingLeft="10dip" 
      a:paddingRight="10dip" 
      a:paddingTop="30dip" 
      android:max="100" > 
     </SeekBar> 

<EditText 
      a:id="@+id/smsBody" 
      a:layout_width="0dip" 
      a:layout_height="wrap_content" 
      a:layout_weight="1.0" 
      a:autoText="true" 
      a:capitalize="sentences" 
      a:hint="@string/sms_enter_message" 
      a:imeOptions="actionSend|flagNoEnterAction" 
      a:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine" 
      a:maxLines="10" 
      a:nextFocusRight="@+id/send_button" 
      a:layout_alignParentBottom="true" /> 

</RelativeLayout> 
+0

只是好奇 - 'a:something =“something_else”'真的适合你吗?不应该是'android:...' – cyborg86pl 2012-07-22 22:16:40

+1

你也指向不存在的元素:'“@ + id/send_button” – cyborg86pl 2012-07-22 22:18:44

+0

@ cyborg86pl:是的,实际上,当我尝试使用android: soemthing =“somethingelse”它不起作用。我不知道为什么 – user836026 2012-07-22 23:23:19

回答

2

您应该使用android:layout_weight来管理元素。例如,以这种方式: 我希望它能工作。

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

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="6" > 

      <SeekBar 
       android:id="@+id/seekBar1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/maplayout" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="6" > 

      <EditText 
       android:id="@+id/smsBody" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:hint="test" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="3" > 

      <com.google.android.maps.MapView 
       android:id="@+id/map" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:apiKey="XXX" /> 
     </LinearLayout> 

    </LinearLayout> 
2

它看起来像你试图直接在MapView上应用布局权重。相反,将MapView放在父容器中,例如一个FrameLayout并应用布局权重,例如0.7到父容器。

1

这是你需要的,可以尝试在任的MapView或其他元素设置该属性:

android:layout_above="@+id/.."android:layout_below="@+id/..."

并删除所有重量属性,它们在RelativeLayout中没有用处,因为您可以使用所描述的属性完成您的工作。 layout_weight通常在LinearLayout中使用,当所有元素都在一个堆栈中,而不是在布局中“塞满”。

当父布局为RelativeLayout时,将使用这些属性,并确定哪些布局应位于另一布局上方,并且通常是整个方向。它还分别有左侧或右侧方向的layout_toLeftOflayout_toRightOf

1

的代码只是两个简单的线条和你用它做:)

android:layout_alignParentBottom="true" 

    android:layout_above="@+id/headerRow" 


<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/bg" > 

    <FrameLayout 
     android:id="@+id/headerRow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="HERE GOES YOUR TEXT" /> 
    </FrameLayout> 

    <com.google.android.maps.MapView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/headerRow" 
     android:apiKey="mykey" 
     android:clickable="true" /> 

</RelativeLayout> 

这一定会帮助你得到你的工作做得完美无缺。

谢谢:)

+0

如果我的答案可以帮助您完成工作,请接受我的答案,我将非常感谢。感谢:D – SALMAN 2012-07-22 23:46:50