Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24424] Calculating of height of label without adding to parent view

GitHub Issuen/a
TypeNew Feature
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterRainer Schleevoigt
AssigneeUnknown
Created2017-02-21T15:49:45.000+0000
Updated2018-02-28T19:55:15.000+0000

Description

Hi, Task: module for measurement (getHeight) of TiUILabel without adding to a parent. I found TiUIView createView(Activity activity) will called after adding to parent view. In a Kroll.method of proxy I call:
private float handleCalculateHeight() {
	TiUILabel textView = new TiUILabel(this);
	int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(300,View.MeasureSpec.AT_MOST);
	int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
	textView.getNativeView().measure(widthMeasureSpec, heightMeasureSpec);
	float h = textView.getNativeView().getMeasuredHeight();
	Log.d(LCAT, "HEIGHT=" + h);
	return h;
}
The result is always 81.0. I think the (JS) options will not proceeded. Any ideas?

Comments

  1. Rainer Schleevoigt 2017-02-22

    I figured the secret i the first paramter of this line:
       tv.measure(View.MeasureSpec.makeMeasureSpec(???,MeasureSpec.EXACTLY),View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED));
       
    Any hints?
  2. Rainer Schleevoigt 2017-02-22

    Solved: ========== @Kroll.method public final float calculateHeight() { float height = 0f; if (TiApplication.isUIThread()) { Log.d(LCAT, "calculateHeight in UIthread"); height = handleCalculateHeight(); } else { TiMessenger.sendBlockingMainMessage(new Handler(TiMessenger .getMainMessenger().getLooper(), new Handler.Callback() { public boolean handleMessage(Message msg) { AsyncResult result = (AsyncResult) msg.obj; result.setResult(handleCalculateHeight()); return true; } }).obtainMessage(0), null); } return height; } private float handleCalculateHeight() { TiUILabel textView = new TiUILabel(this); textView.processProperties(opts); // don't forget ;-) TextView tv = (TextView) textView.getNativeView(); int specWidth = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int specHeight = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); tv.setVisibility(View.VISIBLE); tv.measure(specWidth, specHeight); return tv.getMeasuredHeight(); } ==== Simple add this snippet in the end of LabelProxy.java and with the new method the user can get the calculated height of label.
  3. Sharif AbuDarda 2017-02-22

    Please create a PR of your request.
  4. Rainer Schleevoigt 2017-02-22

    Is there a receipt/howto? A clone is on my machine …

JSON Source