2016-09-07 2 views
0

두 개의 서로 다른 LinearLayout (세로)이 있습니다. 첫 번째 LinearLayout에는 btnX, btnY, btnZ라는 3 개의 버튼이 있습니다. 두 번째 LinearLayout에는 btnA, btnB라는 두 개의 버튼이 있습니다. btnB 상단 정렬은 btnY를 따라야합니다. 새 단추 btnX (가정)를 추가하면 주어진 그림처럼 btnB 높이가 증가합니다. 당신은 그것으로부터 분명한 생각을 얻을 수 있습니다.일치하는 방법 버튼 높이가 다른 linearLayout에있을 때 버튼 높이를 다른 버튼과 비교하려면?

enter image description here

+0

이 레이아웃 코드를 표시의 + 마진 최고입니다, 좋아 당신이 지금까지 시도한 것 –

+0

선형 레이아웃을 사용하지 않고 상대 레이아웃에 모든 것을 넣을 수 있으므로 규칙을 추가하고 동시에 레이아웃 깊이를 줄일 수 있습니다 (따라서 오버 드로). –

+0

LinearLayout에서 원하는대로 작업하지 않는 경우 다른 레이아웃을 사용하는 것이 좋습니다. RelativeLayout은 필요한 것일 수 있습니다. –

답변

0

당신은 레이아웃 무게를 사용할 수 있습니다. 당신은 LinearLayouts에서 , 그리고 android:weightSum=3

를 추가, 각 레이아웃에이를 할당합니다 android:layout_weight=1

그런 식으로, 어떤 버튼에 관계없이 당신이 얼마나 많은 레이아웃의 높이의 1/3을 차지합니다. 버튼의 높이를 2/3로 잡으려면 layout_weight를 2로 설정하십시오.

0

가장 효율적인 해결책은 상대적인 레이아웃을 구현하는 것입니다. 그러나 버튼 B를 다른 독립형 선형 레이아웃에 넣고 상대방 내부의 사람들

0

자세히 설명해주세요. 도움이 되었기를 바랍니다. 변화의 폭과 높이 당신은, 버튼 B의 높이 (버튼 A의 (높이) * 2) 버튼을

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<Button 
    android:id="@+id/btnZ" 
    android:layout_width="216dp" 
    android:layout_height="86dp" 
    style="@style/Widget.AppCompat.Button.Colored" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="24dp" 
    android:text="Button Z"/> 
<Button 
    android:id="@+id/btnY" 
    android:layout_width="216dp" 
    android:layout_height="86dp" 
    style="@style/Widget.AppCompat.Button.Colored" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="24dp" 
    android:text="Button Y" 
    android:layout_below="@+id/btnZ"/> 
<Button 
    android:id="@+id/btnX" 
    android:layout_width="216dp" 
    android:layout_height="86dp" 
    style="@style/Widget.AppCompat.Button.Colored" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="24dp" 
    android:text="Button X" 
    android:layout_below="@+id/btnY"/> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<Button 
    android:id="@+id/btnA" 
    android:layout_width="216dp" 
    android:layout_height="86dp" 
    style="@style/Widget.AppCompat.Button.Colored" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="24dp" 
    android:text="Button A"/> 
<Button 
    android:id="@+id/btnB" 
    android:layout_width="216dp" 
    android:layout_height="196dp" 
    style="@style/Widget.AppCompat.Button.Colored" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="24dp" 
    android:text="Button B" 
    android:layout_below="@+id/btnA"/>