2011-11-12 3 views
3

화면의 위쪽 절반과 아래쪽 절반의 다른 레이아웃 만 채우기 위해 맵을 가져 오려고합니다. 이제는 이것이 테이블 레이아웃과 함께 가중치를 사용하여 가능해야한다는 것을 알고 있습니다. 그러나 동일한 XML 코드 조각은 say 버튼과 완벽하게 작동하지만 맵과는 완벽하게 작동하지 않습니다.
Screenshots here.MapView를 화면 절반으로 제한

XML 코드 : 버튼을 말하여 당신이지도보기 블록을 교체 할 경우 지금은 두 번째 보이는 반면

<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> 

, 그것은, 스크린 샷의 첫 번째 이미지처럼 보이는 것 하나.
두 경우 모두 어떤 가중치 매개 변수 나 layout_width 또는 height를 변경하지 않았지만 어떻게 든 크기가 변경됩니다. 어떤 생각에서 어떻게하면 화면 절반 만 커버 할 수 있습니까?

+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

관련 문제