2012-07-22 37 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