2017-09-04 168 views
0

有人可以向我解釋我的誤解是什麼?對於這兩個佈局我有layout_height = 140dp。但爲什麼他們看起來不同?我該如何解決這個問題?爲什麼這兩種佈局看起來不一樣?

這裏是一個完整的XML的:https://www.pastiebin.com/59ad4fa3d00ba https://www.pastiebin.com/59ad4fd6a20c0

感謝。

enter image description here

enter image description here

第一個是:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="140dp" 
    android:layout_alignParentBottom="true" 
    android:orientation="horizontal"> 

    <Button 
     android:id="@+id/discount_apply" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginRight="2dp" 
     android:layout_weight="1" 
     android:background="@android:color/holo_green_dark" 
     android:paddingLeft="10dp" 
     android:text="ПРИМЕНИТЬ" /> 

    <Button 
     android:id="@+id/discount_cancel" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="2dp" 
     android:layout_weight="1" 
     android:background="@android:color/white" 
     android:paddingLeft="10dp" 
     android:text="ОТМЕНИТЬ" 
     android:textAlignment="center" 
     android:textColor="@android:color/black" /> 

</LinearLayout> 

二是:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="140dp" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 

    <Button 
     android:id="@+id/CashButton" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:drawableLeft="@mipmap/cash" 
     android:paddingLeft="10dp" 
     android:layout_marginRight="2dp" 
     android:background="@android:color/holo_green_dark" 
     android:layout_weight="1" 
     android:text="НАЛИЧНЫЕ" /> 

    <Button 
     android:id="@+id/CardButton" 
     android:layout_width="match_parent" 
     android:background="@android:color/white" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="2dp" 
     android:drawableLeft="@mipmap/visa" 
     android:textColor="@android:color/black" 
     android:textAlignment="center" 
     android:layout_weight="1" 
     android:paddingLeft="10dp" 
     android:text="БАНКОВСКАЯ \n КАРТА" /> 

</LinearLayout> 
+0

在seond佈局中,您使用的是砝碼 –

+0

是的,我明白了,這真的有影響。但我認爲,如果我正在使用android:layout_height,那麼它的表現應該是一樣的。 – Andrew

回答

2

它的安靜難以從這麼多的代碼,但在第二個佈局告知,我在LinearLayout中看到一個layout_weight = 1。如果此LinearLayout的父級是另一個方向設置爲垂直的LinearLayout,則此migth會覆蓋您的高度設置。

+0

Shold我刪除layout_weight標記並設置android:layout_height獲取更少的值? – Andrew

+0

您應該使用_weight或_height,而不是兩者。如果你有一個固定的高度佈局,那麼你應該使用layout_height並去掉_weight。 –

相關問題