Làm cách nào để tôi có thể đạt được bố cục sau, với TextView là TextView
với dấu chấm hết và Xem là wrap_content
và ngay bên phải của TextView?Android - Ellipsize với chế độ xem phù hợp
Dưới đây là ba ví dụ về cách bố trí nên cư xử, với chiều rộng TextView khác nhau:
|[TextView] [View] |
|[TextView TextView] [View] |
|[TextView TextView T...] [View]|
[Chỉnh sửa]
sau đây TableLayout
cho hành vi đúng:
<TableLayout
android:id="@+id/upper_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/alert_button"
android:shrinkColumns="0"
android:stretchColumns="2" >
<TableRow>
<TextView
android:id="@+id/name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:includeFontPadding="false"
android:lines="1"
android:paddingTop="2dp"
android:scrollHorizontally="true" />
<TextView
android:id="@+id/unread_count_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp" />
</TableRow>
</TableLayout>
Các TableLayout
sử dụng 3 cột, cái cuối cùng là hack: thuộc tính strechColumns
làm cho nó chiếm tất cả không gian có sẵn, vì vậy thứ hai TextView
luôn luôn là ngay lập tức bên phải của người đầu tiên. Lần đầu tiên TextView
bỏ qua chính xác do thuộc tính shrinkColumns
.
Tuy nhiên, tôi không thích ý tưởng sử dụng số TableLayout
để đạt được điều đó. Có ai biết cách nào tốt hơn không?
Cảm ơn
Đây có phải là danh sách hay không? – Yury
Vâng, đó là bố cục hàng. – gdelente