[英]Multiline TextView and Singleline TextView in one line
我想在布局中獲得下一個結果:[左文字視圖] [空格] [右文字視圖]為此,我使用它:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="left"
android:id="@+id/left"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="right"
android:id="@+id/right"/>
</RelativeLayout>
沒關系。 但是,如果左側的TextView包含較大的文本,則結果將是下一個:
[left textview](在left textview [right textview]下。因此,左覆蓋right。但是我希望左TextView不覆蓋右,當左TextView到達右TextView時,左TextView進入多行。所以我想下一個結果:
一些文本文本左多行
一些文本文本左多行文本在右文本視圖中
一些文本文本左多行
使用線性布局(水平),並在其中放置具有相同android:layout_weight
textview進行50/50拆分
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
這會使用android:layout_toLeftOf
擴大左側直到到達右側
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/right"
android:text="this is a long text on the left which should be multiline and it is" />
<TextView
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="some text" />
</RelativeLayout>
對您的布局執行此操作:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:minWidth="50dp"
android:maxWidth="100dp"
android:text="right" />
<TextView
android:id="@+id/left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="left"
android:layout_toLeftOf="@+id/right"
android:text="left" />
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.