IDE and View wishes/bugs

Roger Garstang

Well-Known Member
Licensed User
Longtime User
In tooltips for items like Textsize, show what the default value is. I know being new to this stuff and just finished reading the 450+ pages of manuals and looking over most of the forum there wasn't much about it in the documentation other then them not needing dip and sizing correct on their own. First thing I thought before using things was maybe Android got UI design right and just sized the text to properly fit the control...would have made coded layouts without the designer a lot easier than finding out Labels default to 14 and Edit boxes 18.

The CTRL trick to make tooltips fade is nice, but it fades too far...it might as well toggle it on/off. Needs to be just dark/opaque enough to read it and see code under it.

It would be cool if views had a bottom and right attribute. I ended up deciding to just code my layouts, and in positioning views relative to other controls having to do top + height and left + width all the time gets old.

I read in another thread about an imgview with pinch and zoom there was an issue in tabs with -1 values for sizes. First thing I thought was, ok, if -1 just get the parent and use that size for the imgview calculations. Then I realized there is no way to get the parent. Adding a view is all there is. Kind of made the logic confusing in the Designer where there is a dropdown to select a parent, but no parent attribute??? Also, makes it look like views can have multiple parents which I'd think would cause issues.

Where exactly is the -1 size value valid too and why only certain areas? My first thought when reading about it was it could replace 100%x, but there needs to be some way of getting the actual value either with the parent above or another attribute. Expanding on this and making other negative values with special meaning would be cool too...especially if they could apply to flow like setting left=-2 for an Edit Box bumping it right next to the last label added, etc.
 

warwound

Expert
Licensed User
Longtime User
You can read about the native Android layout constants here: ViewGroup.LayoutParams | Android Developers.

int FILL_PARENT Special value for the height or width requested by a View.
int MATCH_PARENT Special value for the height or width requested by a View.
int WRAP_CONTENT Special value for the height or width requested by a View.

FILL_PARENT and MATCH_PARENT are identical, FILL_PARENT has been part of the native Android API since it was first released.
MATCH_PARENT was added from level 8 onwards (Froyo).

If you were writing Java using Eclipse you'd use the constant names.
The underlying values for the constants are:

FILL_PARENT and MATCH_PARENT -1

WRAP_CONTENT -2

Now within the B4A IDE there are some View properties where you can use -1 or -2 for a value and it will work as expected.

Within the Visual Designer though if you set a View width as -1 or -2 then that View will display within the Abstract Designer and on the emulator or device if connected as if that property was set to 0.

But save the layout and load it in an Activity and you'll see that the values -1 and/or -2 are generally applied correctly.

As i said not all Views will display properly if the constant values are used.

As for getting a View width or height if it has not been explicity coded - that's a problem whether you use a constant or just allow the Activity.AddView method to size the View...

The B4A View Width and Height properties will (i think) only return a value if you explicitly set a value.
Otherwise they will return a value of 0.

Things are complicated further by the fact that a View has no layout values until it has been added to an Activity AND the Activity has rendered the View to the display.

I've not found a solution with B4A yet, with Java (let's say Java that's creating a library) you can add an event listener to an Activity.
The event listener listens for the Activity's onGlobalLayout event.
Once the listener has detected that event you can use Java methods to get the rendered size of a View.

You cannot get the rendered size values of a View from B4A though, so if you have not explicitly set Width and Height values you're stuck.

Martin.

(My posts seems to be getting more verbose as time goes by LOL)
 

warwound

Expert
Licensed User
Longtime User
But the problem i find most common is needing the layout values of a View before the Activity has drawn anything to the display.
At this point even the Reflection methods previously referred to would return zero dimensions.

For example:
TouchImageView could do with a method to add an image and scale it to fully fit the TouchImageView.
In Activity_Create that can't be done - the instance of TouchImageView has zero Width and Height just when that method is likely to be executed.
I think (but am not sure) that the same applies in Activity_Resume.

There's no B4A event that can be used to run code after the TouchImageView has been drawn to the display and has real Width and Height values.

Here is the best solution that i've found - it's of little use except in a library unless the Reflection library can do stuff this elaborate:

B4X:
static public void getViewLayout(final View aView) {
   if (aView.getHeight() > 0) {
      //   the View has layout
      //   do something with the layout
   } else {
      //   wait until the View has layout
      final ViewTreeObserver vto1 = aView.getViewTreeObserver();
      vto1.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
         @Override
         public void onGlobalLayout() {
            //   the View has now layout
            //   do something with the layout
            final ViewTreeObserver vto2 = aView.getViewTreeObserver();
            vto2.removeGlobalOnLayoutListener(this);
         }
      });
   }
}

Martin.
 

thedesolatesoul

Expert
Licensed User
Longtime User
But the problem i find most common is needing the layout values of a View before the Activity has drawn anything to the display.
At this point even the Reflection methods previously referred to would return zero dimensions.
I think there is a method that runs before activity_create is fired, that generates the layout values. Only after that, and the views have been drawn can you get the actual width/height. I believe you cannot get them before, even with the code you mentioned above. It only fires when you have the layout (unless you mean you want to do something after the layout has been loaded but before the view is drawn). In that case, you might be able to add a couple of DoEvents in Activity_Create and hope the view is drawn.
I know that the view is drawn for certain in/by Activity_Create, because I used to get the background drawable of a button created with code with the correct width/height.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Weird, WRAP_CONTENT sounds interesting and sort of how I imagined B4A worked until I realized there was default font sizes and Android didn't autosize. Never even touched the Java side and I suggested a -2 value that it uses already...I guess great minds think alike.

I did run into null pointers/references when first laying out code too since I was trying to setup the parameters before adding to the activity. I now just add the view with the dynamic values to 0 and change them after adding. I imagine I will be using things like Reflection a lot as I like to do odd things. .NET for Win Mobile is the same way. I have to use the pInvoke stuff a lot...even for simple things like a 2 line button that the compact framework forgot about.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…