android - Size of a TextView within a widget -


I want to squeeze as much text as possible into a textView of a widget, so I want to hyphenate that text content The easiest way to retrieve the textView size, I think, will display the entire widget with the size of the display. Then I'll increase textual text content and when the number of lines changes, I know where to place the hyphen ('-').

It works to measure off-screen, but it seems that I am setting some dimensions incorrectly because the off-screen method shows new rows , I.e. the actual widget looks more extensive than the reproduction of the off-screen.

What am I doing wrong? Or is there another way of getting what I want?

Here are some code:

1) Off-screen text measurement

  string optimization text (string text) {display display = ((window Manager) getSystemService (reference .windows_SERVICE)) .getDefaultDisplay (); // I know these methods have been deprecated, but the results are the same / when I'm using the new method: display.getSize (point) int displayWidth = display.getWidth (); Int displayHeight = display.getHeight (); LinearLayout Route = New LinearLayout (this); Linear LAYOUT pattern-type = (linear timer) LinearLayout.inflate (This, R. Late. Kal_medium, Root); SampleLayout.measure (display, displaylight); SampleLayout.layout (0, 0, display, displays); TextView character = (text view) sampleLayout.findViewById (R.id.saints); StringBinder Text Hubbar = New StringBuilder (); // result holder int numLines = 1; // always at least one line int len ​​= text.length (); {SaintsView.setText (textBuilder) for (int i = 0; i & lt; len; i ++); If (character view line) (gt; numlines) {System.out.println ("========= Broken AT:" + Text Bilder); // goes to the code that contains HyphenNullins ++; } TextBuilder.append (text.charAt (i)); } Return Text Bulldozer To string (); }   

2) Widget layout file: kal_medium.xml, not completely. Android: layout_height = "fill_parent" Android: layout_width = "fill_parent" Android: layout_alignParentTop = "

  Android: image =" @ + id / img_bg "True" Android : Layout_AllegprintLift = "True" Android: src = "@drawable / bg_post" /> Android: layout_heid = "wrap_parent" android: layout_alignParentLeft = "true" Android: layout_below = "@ id / date" android: layout_marginLeft = "15dp" Android: layout_margin right = "12dp" Android: layout_margin top = "2dp "Android: padding =" 0dp "& gt; Android: layout_height = "wrap_content" Android: singleLine = "false" Android: alipsus = "none" Android: textSize = "Android: 19dp" Android: textstyle = "bold" Android: Gravity = "Center_Water | Left" Android: Paddington = "0dp" Android: layout_margintop = "- 1dp" Android: paddingbottom = "20dp" /> & Lt; / LinearLayout & gt;   

OK, so I left this problem When I was reviewed, I found a solution:

My actual idea proposed in the question work is just one bug in the algorithm for the entry of hyphen. Just make sure that you know what happens in your lines when you insert hyphens.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -