How can I set height/width in percent?

What should I do to make the value as percent?
Like I set Button's height to 10 and it set the height in pixel but when I enter 10% it gives error(NumberFormatException).

So, what value should I write to set the height of a button to 10% ?

Please help @ewpatton

Capture

Leave off the '%' ?

Why is this in the Open Source category?

I am making changes in appinventor sources not making an app.

@preetvadaliya I am doing changes in appinventor sources. Please change the category to Open Source Development again.

okay sorry for that.

1 Like

@Yusuf456 so you want to do like this...

if the user enter "10" then it is pixels value and if the user enter "10%" then it is percent value ?

1 Like

Yes :grinning:

Also, There is a variable in MockVisibleComponent.LENGTH_PERCENT_TAG which has value of -1000. So, will this code work ?

property.setValue(textbox.getText() + MockVisibleComponent.LENGTH_PERCENT_TAG);

I tried this code. It didn't worked for me.

From your code excerpt, I would try (in pseudocode)

if requested width contains '%' then
  extract int w = numeric part of requested width
  set width to LENGTH_PERCENT_TAG - w
else
  do whatever is currently done.

That sets up the negative length (width) attribute to satisfy the embedded code comment's calculations.

Of course, this is just off the top of my head, with no experience here.

3 Likes

What is the context for applying a percent width? There are a lot of moving parts in the system so knowing which one you intend to manipulate is important.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.