2014-06-17 73 views
0

无法理解,为什么按钮的大小不一致。早些时候,我使用LinearLayout而不是RelativeLayout作为根,但是经过一些Google搜索之后,我明白,没有机会使用LL来创建页脚,因此我通过将以前的LL与按钮复制到RL来进行调整,但是.. Look at this. I found it with ruler. It really cut my eyesRelativeLayout中LinearLayout内部按钮的宽度不相等

此外我无法理解,为什么RL中的保证金无法正常工作(我从下面的代码中删除),以及我如何在RL内保证金元素?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout_root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/linearLayout_buttons" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <Button 
      android:id="@+id/button_add" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/all_mentions_Add" /> 

     <Button 
      android:id="@+id/button_delete" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/all_mentions_Delete" /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listView_mentions" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/linearLayout_buttons" > 

    </ListView> 

</RelativeLayout> 

回答

1

刚刚成立的

android:layout_width="wrap_content" 
在你的按钮

android:layout_width="0dp" 

相反,权重的工作(绝招!)

而且在你的LinearLayout

+0

我试图在RL内设置余量。它不会让孩子成为保证金。例如,LL做的。 – Nexen

1
设置 android:orientation="horizontal"

您可以页脚LL:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout_root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ListView 
     android:id="@+id/listView_mentions" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

    </ListView> 

    <LinearLayout 
     android:id="@+id/linearLayout_buttons" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/button_add" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/all_mentions_Add" /> 

     <Button 
      android:id="@+id/button_delete" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/all_mentions_Delete" /> 
    </LinearLayout> 

</LinearLayout> 

如果你想使按键宽度相同而且改变按钮match_parent的宽度。

+0

当一个元素有重量而另一个没有重量时,LL发生了什么?这是否意味着“没有重量的元素将填充所有空间而没有其他元素”? – Nexen

+1

是的,这意味着 –

1
Try this way,hope this will help you to solve your problem. 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <ListView 
     android:id="@+id/listView_mentions" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 


    <LinearLayout 
     android:id="@+id/linearLayout_buttons" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button_add" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/all_mentions_Add" /> 

     <Button 
      android:id="@+id/button_delete" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/all_mentions_Delete" /> 
    </LinearLayout> 
</LinearLayout> 
+0

0dp如何帮助我? O_o为什么纯粹的重量= 1没有这样做? – Nexen

相关问题