我使用輸入字段的解決方案,字段說明採用左側空格,值使用右側空格。它通常有效,但如果最正確的文本太寬,則不會。然後,它只是奠定了最左邊的文本後不是得到它要求的"wrap_content"
的:兩個TextViews共享左右行,當右側文本變得過大時失敗
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:background="@drawable/edittext_background"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@null"
android:ellipsize="end"
android:singleLine="true"
android:text="Make of car"
android:textColor="@android:color/black"
android:textSize="19dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:gravity="center_vertical|end"
android:singleLine="true"
android:text="Ford Focus 2.0 Gold edition with ..."
android:ellipsize="end"
android:textColor="@android:color/black"
android:textSize="@dimen/edittext_value" />
</LinearLayout>
edittext_background
:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/input_field_grey" />
<corners android:radius="6dp" />
</shape>
結果是這樣的:
它的工作原理如下,當值文本佔用的空間大於空間時,只需像這樣省略類型文本:
但是,如果該值文本太寬,類型和值文本省略號被忽略,整個文本只是附加到這樣的權利:
我的目標值文本佔據了所有空間並使用省略號來限制文本,如下所示:
有人有更好的解決方案嗎?
這兩個建議很好地工作,RelativeLayout完全符合我的想法。謝謝! – Aksel