android - A view with an equal width as its sibling but with a limit -


i trying build ui looks :

underline width equal width of text when length of text short

       short text       __________ 

underline width equal limit when length of text long

   sample long text      ____________ 

how can build view underline width adaptive in way described above?

i tried using relativelayout has textview text , empty textview underline (with alignleft , alignright properties) maxwidth property. looks maxwidth property not honored when alignleft , alignright set.

any suggestions achieve appreciated.

you can use following tags in xml:

<view    android:id="@+id/underline"    android:layout_alignleft="@id/textview"    android:layout_alignright="@id/textview"    android:layout_below="@id/textview"/> 

the attributes layout_alignleft , layout_alignright set view aligned start , end of element specify. more information attributes can found on this answer kcoppock.


edit: see tried this, , appears maxwidth ignored. try adding padding programatically when set text of textview, this:

if(textview.getwidth() > maxwidth){    // amount went on    int remaininglength = textview.getwidth() - maxwidth;    // cut in half    int paddinglength = remaininglength / 2    // set left/right padding center line    lineview.setpadding(paddinglength, 0, paddinglength, 0); } 

here documentation setpadding().


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -