Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to calculate button width before addView
    primarykey
    data
    text
    <p>I adding buttons into Horizonatal linearlayout programally, and I want know this button width before layout.</p> <p>It's because if buttons's total width over LinearLayout width, App create new LinearLayout below old LinearLayout.</p> <p>button has 1byte char and multibyte char.</p> <p>therefore,case of button width when button has only 1byte char, case of button width when button has only multibyte, button width is difference.</p> <pre><code>public void draw() {          width = 320;//screen width Button btn; int i; int twidth = 0; LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); lparams.setMargins(0, 5, 0, 5); LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); buttonParams.setMargins(5, 0, 5, 0); for (i = -1; +i &lt; size(); i++) { LinearLayout layout2 = new LinearLayout(context); layout2.setOrientation(LinearLayout.HORIZONTAL); addView(layout2, lparams); twidth = 0; while (twidth &lt; width &amp;&amp; i + 1 &lt; size()) { btn = new Button(context); btn.setText(element.get(i + 1).tagName); btn.setTextColor(Color.BLACK); btn.setBackgroundColor(Color.WHITE); btn.setMaxLines(1); btn.setLayoutParams(buttonParams); twidth += btn.getTextSize() * btn.length() + 10; if (twidth &gt;= width) { i--; break; } else { btn.setPadding(5, 0, 5, 0); btn.setClickable(true); btn.setId(element.get(i + 1).tagId); layout2.addView(btn, buttonParams); i++; } } } } </code></pre> <p>is there solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload