[英]android relativelayout two rows with column on the right
我正在嘗試用浮動的(右)TextView在左側獲得兩行,該行將有一個數字。 這是一個列表視圖項的布局。
____
___________________________ | |
___________________________ |____|
所以內容就像
LINE ONE CAN SOMETIMES BE LONG £2000.00
line two
但是,£2000.00(較大的文本大小)與下面的代碼示例重疊,或者通過使用android:layout_toRightOf="@+id/row1"
覆蓋,它基本上位於row1旁邊,如果row1很長,則有時會排在下一行。 它應該始終在一行中。
有人可以幫忙嗎?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dp" >
<TextView
android:id="@+id/row1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold" />
<TextView
android:id="@+id/rightcol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#cc0000"
android:textSize="22dp" />
<TextView
android:id="@+id/row2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/row1" />
</RelativeLayout>
這樣,右列文字與row1重疊
感謝您的檢查
android:layout_weight
將是實現你想要的布局(見有用此 )。 您可以使用android:layout_width="wrap_content"
代替右側的50dp文本視圖。 其他TextView將調整以填充剩余空間。 您可以使用android:singleLine="true"
來限制您的TextView,以便它們不會換行。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"/>
</LinearLayout>
如果您設置使用RelativeLayout,則應該可以使用。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dp" >
<TextView
android:id="@+id/row1"
android:text="This text can be very, very long"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/rightcol"
android:textStyle="bold" />
<TextView
android:id="@+id/rightcol"
android:text="$2000000000000.00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#cc0000"
android:textSize="22dp" />
<TextView
android:id="@+id/row2"
android:text="Second line of text"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/rightcol"
android:layout_below="@+id/row1" />
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.