android - How to use textview.getLayout()? It returns null -
i’m trying set layout textview
can use getellipsiscount()
method. below code returns null layout value. how can take layout , use getellipsiscount(0)
method.
public class mainactivity extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); textview mytextview =(textview) findviewbyid(r.id.textview1); mytextview.settext(mytext); layout layout = mytextview.getlayout(); if(layout != null){ mytextview.settext("very layout worked\n"); } }
you calling early, thats why returning null
try this
viewtreeobserver vto = mytextview.getviewtreeobserver(); vto.addongloballayoutlistener(new ongloballayoutlistener() { @override public void ongloballayout() { layout layout = mytextview.getlayout(); } });
Comments
Post a Comment