2017-09-04 165 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。 –

相关问题