【发布时间】:2017-12-17 22:25:05
【问题描述】:
我正在尝试将一对 TextViews 对齐在一行 EditText 的任一侧。对此的一些警告:
- 我希望它们彼此紧紧地拉在一起,所以对于
EditText右侧的TextView,我想确保没有太多空间 -
TextViews可能存在也可能不存在,具体取决于客户设置,但需要在运行时确定。因此,如果我将TextViews中的一个或两个的可见性设置为 NONE,则字段需要转移。 - 所有 3 个字段都需要在屏幕上向右拉。
- “后缀”(右侧的
TextView)的大小最多为 10 个字符,但我希望它能够自动填充所需的空间。
这是我希望看到的:
但这是我目前所拥有的:
如您所见,前缀和后缀($ 和 US)合并在一起,而不是在 EditText 的每一侧分开。我在所有相关领域都使用了android:layout_height 和android:layout_width,但没有达到预期的效果。
我尝试了TableLayout,但由于我需要将EditText 值向右移动,如果没有TextView 向右移动(在本例中为后缀或“US”),我认为这不会工作(除非我在那里遗漏了一些东西)所以我得到了以下内容,我认为它正在接近并且代表上面的当前屏幕截图:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="normal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:text="Test" />
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:focusable="true"
android:focusableInTouchMode="true">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$" />
<EditText
android:id="@+id/entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="12456"/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="US" />
</RelativeLayout>
<View
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:visibility="gone" />
</LinearLayout>
【问题讨论】:
标签: android android-layout android-linearlayout android-relativelayout