Tôi đang cố gắng để có được một hàng chữ sẽ được cái gì đó nhưbố trí sử dụng Android layout_weight, layout_width và maxWidth
foofoofoo - barbarbar
nhưng tôi muốn nó elip foo và bar nếu nó đã giành' t phù hợp trên một dòng. tức là tôi đang cố gắng rút ngắn chúng xuống.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="0dip"
android:layout_weight="1"
android:textColor="#ffffff"
android:singleLine="true"
android:ellipsize="true"
android:text="foofoofoofoo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text=" - " />
<TextView
android:id="@+id/text_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="0dip"
android:layout_weight="1"
android:textColor="#ffffff"
android:singleLine="true"
android:ellipsize="true"
android:text="barbarbarbar" />
</LinearLayout>
Hãy để tôi làm việc này một phần.
Thiết lập 's layout_width
TextView
là 0dip
và layout_weight
là 1
nghĩa là họ sẽ mất 50% của không gian có sẵn mỗi.
Thiết lập singleLine
để true
và ellipsize
để true
nghĩa là họ sẽ trông giống như foofoo ... nếu văn bản lớn hơn thùng sơn.
Do đó kết quả của tôi (nếu văn bản dài) nên
foofoo .. - Barbar ..
Mà nó là! Vì vậy, điều này hoạt động.
Bây giờ trường hợp tôi đang cố gắng để sửa chữa là, nếu là người đầu tiên TextView
(id: bản_1) có văn bản đó là ít hơn 50% do layout_width="0dip"
và layout_weight="1"
Tôi muốn nó wrap_content
. Nếu không nó trông giống như:
fookhông gian trống- Barbar ..
và tôi muốn
foo - barbarbar
Đây là lý do tại sao tôi đã thay đổi layout_width="wrap_content"
và thêm android:maxWidth="0dip"
nhưng điều này không hoạt động! Dường như bỏ qua tôi nói rằng wrap_content
và vẫn cho chế độ xem này 50%!
Tôi đọc rằng bạn cần thêm android:adjustViewBounds="true"
cho maxWidth
để hoạt động nhưng điều này không ảnh hưởng.
Xóa android: stretchColumns = " 0,2 ", và nó hoạt động. Cho đến nay anyway! :-) cảm ơn – Blundell
@Blundell wow, tôi là một thợ săn tiền thưởng! vui vì nó đã làm việc và cảm ơn bạn vì giải thưởng. – bigstones
Giúp cả hai chúng tôi. Tôi là một ân nhân :-D – Blundell