android - Get string length in pixels -


i have layout looks follows:

|user name      |      | |email@mail.com | info | 

and need set user's first name , second name if fits textview , first name if first name , second name long current screen.

for example "tom smith":

|tom smith      |      | |email@mail.com | info | 

and "tom veryveryverylongsurname":

|tom            |      | |email@mail.com | info | 

how can name size specified text size , compare textview width?

<linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:orientation="horizontal">      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_weight="1"         android:orientation="vertical">          <textview             android:id="@+id/name"             android:layout_width="wrap_content"             android:layout_height="wrap_content"/>          <textview             android:id="@+id/email"             android:layout_width="wrap_content"             android:layout_height="wrap_content"/>     </linearlayout>      <textview         android:id="@+id/info"         android:layout_width="wrap_content"         android:layout_height="match_parent"         android:gravity="bottom"/> </linearlayout> 

see textpaint#gettextbounds method http://developer.android.com/reference/android/graphics/paint.html#gettextbounds%28char[],%20int,%20int,%20android.graphics.rect%29

and other textpaint , paint classes

paint.html#measuretext seems more matching looking for. http://developer.android.com/reference/android/graphics/paint.html#measuretext%28java.lang.charsequence,%20int,%20int%29

anyway @ android.graphics.paint class.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -