tôi đang cố gắng để làm một listview mà trông như thế này: alt text http://pici.se/pictures/hjFksZvLx.jpgCăn chỉnh phải và trái với tuyến tính hoặc relativelayout với văn bản cắt ngắn?
Nó có hai phần, bên trái được canh trái và chứa hai TextView là dòng đơn và cắt ngắn. Bên phải là một phần cũng có hai lần xem văn bản nhưng chúng được căn phải và có kích thước không đổi. Vấn đề chính là phần bên phải không thẳng hàng bên phải. Nếu tôi sử dụng một chiều rộng tĩnh để đẩy nó sang bên phải nó hoạt động khá tốt, nhưng sau đó nó không nhìn tốt trong chế độ phong cảnh.
Tôi nghĩ rằng nó phải đơn giản để thực hiện. Nhưng không phải vậy.
Trước tiên tôi thử với LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:id="@+id/L1"
android:layout_height="fill_parent"
android:layout_weight="0.8"
android:layout_width="0dip">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="Long text Long text Long text Long text Long text Long text Long text" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="Short text" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:id="@+id/L2"
android:layout_gravity="top|right"
android:layout_height="fill_parent"
android:layout_weight="0.2"
android:layout_width="0dip">
<TextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="12:12" />
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="64%"
android:layout_gravity="right" />
</LinearLayout>
</LinearLayout>
Tôi đã loay hoay với thuộc tính trọng lượng, nhưng nó không có vẻ để giúp đỡ. Phần bên phải không thẳng hàng với bên phải.
Và sau đó tôi thử với RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:id="@+id/text1"
android:layout_height="wrap_content"
android:lines="1"
android:scrollHorizontally="true"
android:layout_alignParentTop="true"
android:text="Long text Long text Long text Long text Long text Long text Long text"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:layout_width="275dp" />
<TextView
android:id="@+id/text2"
android:layout_height="wrap_content"
android:lines="1"
android:ellipsize="end"
android:scrollHorizontally="true"
android:text="Long text Long text Long text Long text Long text Long text Long text"
android:layout_below="@+id/text1"
android:layout_alignParentLeft="true"
android:layout_width="275dp" />
<TextView
android:id="@+id/text3"
android:layout_height="wrap_content"
android:text="12:12"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:layout_alignBaseline="@+id/text1"
android:layout_width="40dp"
android:layout_alignRight="@+id/text4" />
<TextView
android:id="@+id/text4"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="64%"
android:layout_alignParentRight="true"
android:layout_alignBaseline="@+id/text2"
android:layout_width="40dp" />
</RelativeLayout>
Cùng một vấn đề ở đây, phần bên phải không được sắp xếp ở bên phải đúng cách, và tôi phải sử dụng một kích thước tĩnh của android: layout_width để đẩy nó vào mặt khác. Và nếu không sử dụng kích thước tĩnh, văn bản bắt đầu cắt nhau.
Cảm ơn bạn .. Tôi đã hy vọng sẽ tránh được thêm Linearlayout, nhưng đó là cách duy nhất hoạt động. – droidgren
Điểm trong gói LinearLayout trong RelativeLayout là gì. LinearLayout bây giờ là con duy nhất của RelativeLayout và cha mẹ có lẽ có thể bị loại bỏ? –
@GlennBech: Có nhiều tiện ích con bên trong 'RelativeLayout', không chỉ là' LinearLayout'. – Macarse