Android Question Working with Buttons programmatically

mbatgr

Active Member
Licensed User
Longtime User
Is there any way of how to identify which buttons has been created by code and then to remove thm by code before procceeding in recreating some new ones by code too.
Also, I have made a little program on my tablet 1980x1120, scale 2. It is well working but I have not get well how I will make them readjusted on other tablets screen modes. Should I have to use Autoscale or Autosize (I' m using script designer) ?
Or is better to transform the dips to % based on my screen dimensions like in the examples given on the forum?
mike
 

klaus

Expert
Licensed User
Longtime User
Is there any way of how to identify which buttons has been created by code and then to remove thm by code before procceeding in recreating some new ones by code too.
You are the developper, so I expect you knowing wich button you want to remove and replace by another one.
There is no difference between a Button added in the Designer or in the code.
What is the purpose of removing Buttons and generate new ones ?
You could 'play' with the Visible property to hide and show them or change their text or images.

For layouts for different screen sizes and resolutions you could use AutoScale in the DesignerScripts or the AutoScale module or use %x and %y values.
Be aware that a 10'' screen has a surface 8 times bigger than a 3.5'' screen.
And a 10'' screen has a surface double of a 7'' screen.
So a layout designed for a 3.5'' screen and streched for a 10'' screen will look awfull.
A layout designed for a tablet may look too small on a phone.

- AutoScale in the DesignerScripts allows scaling only views added in the Designer and based on the standard screen size (320 / 480 / 160).
- The AutoScale module allows to scale Views added in the code.

Did you read chapter 8.10 AutoScale in the Beginner's Guide.
 
Upvote 0

mbatgr

Active Member
Licensed User
Longtime User
Yes this is true. i can scan the controls and based on its tag to remove the apropriate one. But I prefer to exit the app and running on the background (pause) and when user brings the app back, to resume it and rerun the code from the beggining.

I have read it but I feel that something is missing. I' m NOT using script designer, just pure code. Maybe I have not get grasp the way things work on tablets. My app will be running only on landscape mode and 7+ tablets. I prefer to do things programatically. I have the sense that is not difficult to make the scale/resizing programmatically based on physical device screen characteristics (W, H, scale parameters) but the discussion about this matter makes me believe that something is missing to me. Is this true? For example, why one can use the rate value described on the beginner's manual?

Also, is it true I have to add different Layouts Variants (using the designer) in order my app to support them? And if a certain Layout is not there, it is not possible for me to adjust "on-air" programmatically the size and the position of controls (views)?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
My app will be running only on landscape mode and 7+ tablets.
In this case I'd suggest you to use %x and %y values.
For example, why one can use the rate value described on the beginner's manual?
This depends on what you want to display and how. I the AutoScale module in the RPNCalculator and the TapeCalculator. Both work on 3.5'' screens up to 10'' screens. Three layout files with one variant each and adjusted in the code.
Also, is it true I have to add different Layouts Variants (using the designer) in order my app to support them?
No, but you can. The problem with several layout variants is that when a new device comes out its screen resolution is not necessarily supported. It can be useful to have one layout variant for portrait and one for landscape but this not your case.
And if a certain Layout is not there, it is not possible for me to adjust "on-air" programmatically the size and the position of controls (views)?
You can adjust every view afterwards in the code.

There is no unique principle on how managing different screen sizes and resolutions. It depends on the kind of application, the target devices and what you want to display at the same time depending on the screen size.
You can, for example, display 2 panels side by side on a big screen but not on a small screen so you need to handle them differently on big screens than on small screens. I have recently written a music playing program for my 10'' tablet (not published). Then I wanted it on my new phone with a 5'' screen, I have written a separate project. I have not yet tried to merge both together because the layouts are quite different.
 
Upvote 0
Top