2016-03-07 88 views
0
卸下侧面间距

我有这样的布局设计到目前为止从按钮的LinearLayout

enter image description here

通知各地都名为“拯救”,我用红色标出的按钮侧的空间,我想去除多余的间距。

这两个按钮都被包裹在linearlayout中,方向设置为“vertical”,我试过使用layout_weight, marginLeft and marginRight但没有成功。

这里的XML代码看起来像只针对的LinearLayout里面的按钮

<LinearLayout 
     android:id="@+id/buttonSection" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 

     > 
     <!--This layout is for save and change currency buttons--> 


     <Button 
      android:id="@+id/saveButton" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Save" 
      android:layout_weight="1" 
      /> 

     <Button 
      android:id="@+id/currencyButton" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Save" 
      android:layout_weight="1" 
     /> 
    </LinearLayout> 

只是额外的信息上面的LinearLayout被包裹多一个的LinearLayout控制充满活动的布局里面

编辑

主要活动xml文件的完整代码

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:background="@drawable/layer_list" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_main" 
    tools:context=".MainActivity" 
    android:orientation="vertical" 
    android:weightSum="5" 
    > 

    <LinearLayout 
     android:id="@+id/layout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_weight="2" 
     android:paddingTop="10dp" 
     android:layout_marginBottom="30dp" 
     > 

     <LinearLayout 
      android:id="@+id/leftCurrencySection" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_weight="1" 
      android:orientation="vertical" 

      > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="GBP" 
       android:textSize="30dp" 
       android:textColor="#ffffff" 
       android:textAllCaps="true" 
       android:textStyle="bold" 
       /> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="0.00" 
       android:textSize="30dp" 
       android:textColor="#ffffff" 
       android:textAllCaps="true" 
       android:textStyle="bold" 
       android:background="@null" 
       /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/rightCurrencySection" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="right" 
       android:text="USD" 
       android:textSize="30dp" 
       android:textColor="#ffffff" 
       android:textAllCaps="true" 
       android:textStyle="bold" 
       /> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="right" 
       android:text="0.00" 
       android:textSize="30dp" 
       android:textColor="#ffffff" 
       android:textAllCaps="true" 
       android:textStyle="bold" 
       android:background="@null" 
       /> 

     </LinearLayout> 

    </LinearLayout> 
    <!--End of This layout is for typing currency values--> 

    <LinearLayout 
     android:id="@+id/buttonSection" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 

     > 
     <!--This layout is for save and change currency buttons--> 


      <Button 
       android:id="@+id/saveButton" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Save" 
       android:layout_weight="1" 
       /> 

       <Button 
        android:id="@+id/currencyButton" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Save" 
        android:layout_weight="1" 
        /> 
    </LinearLayout> 
    <!--End of save and change currency buttons--> 

    <!--Begin Layout for calculator begin--> 

    <GridLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:columnCount="3" 
     android:layout_gravity="center" 
     android:orientation="horizontal" 
     android:layout_weight="1" 
     > 


     <Button android:text="1" 

      /> 

     <Button android:text="2" /> 

     <Button android:text="3" /> 



     <Button android:text="4" /> 

     <Button android:text="5" /> 

     <Button android:text="6" /> 



     <Button android:text="7" /> 

     <Button android:text="8" /> 

     <Button android:text="9" /> 


     <Button android:text="." /> 

     <Button android:text="0" /> 

     <Button android:text="Del" /> 


    </GridLayout> 
    <!--End Layout for calculator--> 
    <!--End Layout for calculator End--> 


</LinearLayout> 
+0

你可以发布你正在使用的整个XML文件,如果这是一个片段,那么你的主要活动XML文件? – eclipse1203

+0

在Button属性android:layout_width =“match_parent”;中删除父级布局容器 –

+0

的填充。 –

回答

0

有很多人要感谢这里,谁指出我的错误,并指导我正确的方式从按钮的两侧删除多余的空间。

第一个我不得不从我父母linearlayout删除填充。我删除了paddingLeft和PaddingRight。其中删除了空间的主要部分。感谢cricket_007指出了这一点。

即使删除空间后仍然有一点空间,如1或2dp。这显然是由于Android中的一些默认样式,如Doug Stevenson所指出的。

要删除的空间最后的形式,我不得不运用某种背景,通过月食例如android:background="#00ff00"

应用去除多余的空间,这是由于在android系统,以9patch上面提到的属性。 Learn more about it over here.