Long Android TextView pushes other views off-screen -


i've got 2 textviews side-by-side. textview1 has varying length of text, , textview2 says "+#". when textview1 gets long however, pushes textview2 off screen. ideas how fix this? here's layout code:

    <relativelayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal">          <textview             android:id="@+id/textview1"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:singleline="true"             android:ellipsize="end"             android:textsize="13sp"/>          <textview             android:id="@+id/textview2"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:singleline="true"             android:textsize="13sp"/>      </relativelayout> 

this i've tried solve while now. unfortunately, method others have suggested - using layout_weight inside linearlayout - doesn't work; however, i've found solution you!

<relativelayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:gravity="left">      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_toleftof="@id/textview2"         android:singleline="true"         android:ellipsize="end"         android:textsize="13sp"/>      <textview         android:id="@+id/textview2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentright="true"         android:singleline="true"         android:textsize="13sp"/> </relativelayout> 

with above block, use relativelayout in order align first textview left of second textview. align second textview right side of parent viewgroup. finally, add android:gravity="left" parent viewgroup in order align of textview's left.

this results in both textview's being side side - regardless of first textview's length. if first textview have multiple lines, remove android:ellipsize="end" tag.

hopefully expected outcome!


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -