2011-03-31 11 views
5

화면을 2 개의 섹션으로 나누려고합니다. 위의 섹션은지도 위젯입니다. 다음은 위젯으로 채워진 다른 레이아웃입니다. 문제는지도 위젯이 전체 화면을 채우는 것입니다. 지도 아래의 레이아웃을 어떻게 만들 수 있습니까?Android 레이아웃 우선 순위

지도 위젯에 높이를 부여하여 해결할 수 있다고 생각하지만 매우 유연하지는 않습니다.

내이 시도 :

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



    <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:apiKey="my api key" /> 





    <RelativeLayout 
     android:id="@+id/map_menu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/mapview" 
     android:background="@drawable/locatie_background" > 


     <Button android:id="@+id/firstButtonId" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" android:text="@string/action_ready" 
      /> 

    </RelativeLayout > 

</RelativeLayout> 
+0

다음을 시도해보십시오. RelativeLayout에서 android : layout_weight = "1" 나는 그것이 당신의 문제를 해결할 것이라고 생각한다. –

+0

@ 카틱 아니, 그렇지 않을 것이다. 'layout_weight'는'RelativeLayout'에 의해 무시됩니다. –

+0

팁 주셔서 감사. 부모 레이아웃을 linearLayout으로 변경하려고 했으므로 두 번째 상대 레이아웃에 가중치를 할당 할 수 있습니다. 하지만 같은 결과를 내고 있습니다. – Vincent

답변

1
대신 RelativeLayout의의

같이있는 LinearLayout 사용을 : 그들이 여기처럼 퍼센트 값을 것처럼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:clickable="true" 
     android:apiKey="my api key" /> 
    <RelativeLayout 
     android:id="@+id/map_menu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_below="@id/mapview" 
     android:background="@drawable/locatie_background"> 
     <Button android:id="@+id/firstButtonId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/action_ready" /> 
    </RelativeLayout > 
</LinearLayout> 

당신은 layout_weight 작업 할 수

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 


<LinearLayout 
    android:id="@+id/map_menu1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    > 

    <com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:clickable="true" 
    android:apiKey="my api key" /> 
</LinearLayout > 

<LinearLayout 
    android:id="@+id/map_menu" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    > 

    <Button android:id="@+id/firstButtonId" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="action_ready" 
     /> 

</LinearLayout > 

</LinearLayout> 
+0

감사합니다, 이것은 내가 찾고있는 것입니다 – Vincent

+4

기술적으로는 정확하지만 불필요한 두 번째 'LinearLayout'은 -1의 가치가있었습니다. –

+0

@ karthi octavian이 맞습니다 .. 추가 메모리 .. –

1

이 당신의 코드를 대체하십시오 LinearLayout

<?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="wrap_content" 
android:orientation="vertical"> 



<com.google.android.maps.MapView 
    android:id="@+id/mapview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:apiKey="my api key" /> 





<RelativeLayout 
    android:id="@+id/map_menu" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/mapview" 
    android:background="@drawable/locatie_background" > 


    <Button android:id="@+id/firstButtonId" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="@string/action_ready" 
     /> 

</RelativeLayout > 

</LinearLayout> 
+0

이것은 효과가 없을 것입니다. –

+0

그것은 작동 할 것이다 ... 나는 그것을 검사했다 – Udaykiran

+0

나는 틀린 질문을 추측한다. 죄송합니다. –

4

이동, wrap_content에 두 아이의 layout_height을 설정하고 1에 모두의 layout_weight을 설정합니다.

이 동일하게 화면의 높이를 나눌 것입니다 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="90" 
     android:clickable="true" 
     android:apiKey="my api key" /> 
    <RelativeLayout 
     android:id="@+id/map_menu" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" 
     android:layout_below="@id/mapview" 
     android:background="@drawable/locatie_background"> 
     <Button android:id="@+id/firstButtonId" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/action_ready" /> 
    </RelativeLayout > 
</LinearLayout> 
+1

내가 trie이 오류 : 정수 형식 (값 '0'으로 'layout_height'에서) 허용되지 않습니다. – Vincent

+0

내 실수를 수정했습니다. –

+0

다른 질문이 있습니다. 나는 두 번째 레이아웃에 10 개 버튼을 넣는 대신 1 개를 넣으려고 시도했지만 레이아웃이 배경의 높이보다 더 많이 찌르지는 않는다. 이게 정상인가? – Vincent