android - Expand TextView with wrap_content until the neighbor view reaches the end of the parent -
i need achieve following layout:
i have 2 textviews in relative layout: green 1 fixed text wrap_content
, black 1 has dynamic text wrap_content
. black text can change , become long. want black textview expand text until green view reaches end of parent. if happens, black textview should stop expanding , ellipsize end.
how can achieve that?
what tried:
<relativelayout android:id="@+id/parent" android:layout_width="match_parent" android:layout_height="wrap_content" > <textview android:id="@+id/lefttextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxlines="1" android:layout_alignparentleft="true" android:textsize="18sp" /> <textview android:id="@+id/righttextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/lefttextview" android:textsize="18sp" /> </relativelayout>
but when black text gets bigger , bigger pushes green 1 out of view
you can archive layout tablelayout
, shrinkcolumns
attribute.
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- row 1 --> <tablelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkcolumns="0"> <tablerow android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4dp" android:maxlines="1" android:ellipsize="end" android:text="abcdefghijklmnopqrstuvwxyz"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4dp" android:maxlines="1" android:ellipsize="none" android:text="righttext"/> </tablerow> </tablelayout> <!-- row 2 --> <tablelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkcolumns="0"> <tablerow android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4dp" android:maxlines="1" android:ellipsize="end" android:text="longer text view abcdefghijklmnopqrstuvwxyz"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4dp" android:maxlines="1" android:ellipsize="none" android:text="righttext"/> </tablerow> </tablelayout> <!-- row 3 --> <tablelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkcolumns="0"> <tablerow android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4dp" android:maxlines="1" android:ellipsize="end" android:text="text view logn , not fit parent width abcdefghijklmnopqrstuvwxyz"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="4dp" android:maxlines="1" android:ellipsize="none" android:text="righttext"/> </tablerow> </tablelayout> </linearlayout>
here same question ;)
Comments
Post a Comment