Generate number of columns dynamically according to screen size in android grid layout -


i using grid layout has textview implement drag , drop in android. have problem in generating number of columns changing textview size according text area. eg. if textview contains word "test" width of textview according that.

i used below code generate number of columns according screen size

    float scalefactor = getresources().getdisplaymetrics().density * 100;     number = getwindowmanager().getdefaultdisplay().getwidth();     columns = (int) ((float) number / (float) scalefactor); 

when use code, generates same number of columns regardless of width of textview. eg. getting output like,

output

my expected output ,

expectedoutput

i want textview adjust automatically in first row since space available in first row. in short, want column count increment stop once width of phone reached. tried below code,

    int static totaltextarea ;     totaltextarea = totaltextarea + widths; //widths text area of textview     if(totaltextarea <=number) //number screen width      {      columncount++      } 

it didn't me. columns going out of screen when implement methods. please help.

p.s : want textview width width of text area .


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -