Android间距

Android spacing

我在使用线性布局的 spacing/laying 出视图时遇到问题。在模拟器中,布局看起来很完美。但是,当我在实际的 android 平板电脑上进行测试时,布局不正确。有关我在平板电脑上看到的图像,请参阅 link。

Device Layout Example

这就是我在模拟器上看到的:

Emulator Layout Example

我已经在 XML 中定义了视图:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

<TextView
    android:id="@+id/sample"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="sample"
    android:textSize="14sp"/>

<Space
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

<EditText
    android:id="@+id/sample"
    android:layout_width="201dp"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@id/sample"
    android:hint=""
    android:inputType="numberDecimal"
    android:text="@={config.sample}"
    android:textAlignment="center"/>
</LinearLayout>

我真的不知道是什么导致此代码在模拟器中显示正常,但在设备上出现问题。我想我可以为文本视图使用定义的宽度,但感觉这不是正确的答案。基本上我需要一个文本视图,一个 space 或边距,然后编辑文本视图全部均匀 spaced,即使文本视图中的文本可能具有不同的长度。

您可以进行一些更改,例如

 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="10">

    <TextView
        android:id="@+id/sample"
        android:layout_width="0dp"
        android:layout_weight="4"
        android:layout_height="wrap_content"
        android:text="sample"
        android:textSize="14sp"/>

    <Space
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2"
        />

    <EditText
        android:id="@+id/sample"
        android:layout_width="0dp"
        android:layout_weight="4"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/sample"
        android:hint=""
        android:inputType="numberDecimal"
        android:text="@={config.sample}"
        android:textAlignment="center"/>
    </LinearLayout>