对齐TextView,Button,EditText

时间:2013-02-14 15:36:55

标签: android alignment

如何将TextView和Button对齐到左边,将EditText和Button对齐到右边?这是包含未对齐项目的表单。

enter image description here

我的xml文件是:

<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

<RelativeLayout
    android:id="@+id/PlateEntryRelativeLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/RequestButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/PlateEdit"
        android:text="@string/request" />

    <TextView
        android:id="@+id/PlateTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/PlateEdit"
        android:layout_alignBottom="@+id/PlateEdit"
        android:layout_alignParentLeft="true"
        android:text="@string/plate"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/PlateEdit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@android:drawable/editbox_background"
        android:ems="10"
        android:gravity="right|center_vertical" />

</RelativeLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="false"
        android:text="ToggleButton" />

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

您可以简单地将其添加到textview

android:paddingLeft="4dp"

但我建议你查看这个问题 Can't get rid of bottom padding on button