我有这样的布局设计到目前为止从按钮的LinearLayout
通知各地都名为“拯救”,我用红色标出的按钮侧的空间,我想去除多余的间距。
这两个按钮都被包裹在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>
你可以发布你正在使用的整个XML文件,如果这是一个片段,那么你的主要活动XML文件? – eclipse1203
在Button属性android:layout_width =“match_parent”;中删除父级布局容器 –
的填充。 –