2011-11-12 10 views
3

マップの上半分のみを塗りつぶし、下半分に他のレイアウトを塗りつぶしようとしています。今私はこれがテーブルレイアウトと組み合わせて重みを使って可能でなければならないことを知っています。しかし、同じXMLコードは、ボタンでは完全に動作しますが、マップでは機能しません。
Screenshots hereMapViewを画面の半分に限定する

XMLコード:ボタンを言うことであなたはMapViewのブロックを交換する場合、今、それは第二のように見えるのに対し、

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
      <com.google.android.maps.MapView 
      android:id="@+id/map2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:apiKey="0_z4IHjB6EnXohnoyoudontgoVmhg" 
      android:clickable="true" > 
     </com.google.android.maps.MapView> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
     <Button android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="SECOND"></Button> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
     <Button android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="SECOND"></Button> 
    </TableRow> 
</TableLayout> 

が、それは、スクリーンショットの最初の画像のようになります。 1。
どちらの場合も、ウェイトパラメータやlayout_widthやheightは変更しませんでしたが、サイズを変更してしまいました。どのようにしてMapViewを画面の半分だけカバーすることができますか?

+0

私は唯一の方法は、プログラムでそれを行うことだと思います。 –

+0

これはどのように行われるのですか? – Urban

+1

あなたは 'TableLayout'と' TableRow'で 'layout_width'と' layout_height'を使用しません。入れ子にされた 'LinearLayouts'に切り替えたり、' RelativeLayout'などを使用してください。 – CommonsWare

答えて

5

申し訳都市は、それの上にあなたのお尻ステアを与えた - 私はこの前に見ていたし、私はマップのサイズを制限することができる唯一の方法は、プログラムでは、しかし、私はこのタイプのレイアウトでそれを行っているので、だった:

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

<FrameLayout android:id="@+id/map_frame" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.7" >  

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

</FrameLayout> 

<co.uk.mycompany.ui.MapNavBar 
    android:id="@+id/map_nav" 
    android:layout_width="fill_parent" 
    android:layout_height="70dip" 
    android:layout_gravity="bottom" 
    android:layout_weight="0.3" /> 

示す最後の項目は、カスタムウィジェットですが、レイアウトが関与の原則を示すべきです。これはマップの高さを制限しましたが、フルハイトにすることを可能にしました。

+0

Thx @John。私はLinearlayoutを代わりに使用しましたが、基本的には同じものです...私がテーブルを最初に使用した理由はわかりません> – Urban

関連する問題