Note that there are some explanatory texts on larger screens.

plurals
  1. PONew to Android, need custom layout similar to AbsoluteLayout
    primarykey
    data
    text
    <p>I've been looking into creating a custom layout based on ViewGroup, and I get (I think) the concept on which layouts are based. Some of it, anyway.</p> <p>It seems that the basic idea is</p> <ul> <li>first ask all your child views how big they want to be - in onMeasure()</li> <li>calculate a layout based on that</li> <li>position them all based on their desired sizes - in onLayout()</li> </ul> <p>It's a bit like a web page layout, I suppose.</p> <p>However, I don't want to do that at all. Based on the available screen real estate (x/y px) I have a whole load of child views (various text, button, freeform graphics) that I need to define the dimensions of, set text sizes for, and then position. Ie I am not remotely interested in how big they would like to be, I want to tell them how big they will be and where they will be.</p> <p>There is (was) an AbsoluteLayout that does something similar, but it is depreciated.</p> <p>Since the layout is totally tied in with the children (completely fixed number for the job) and screen size, I am proposing to:</p> <ul> <li>Create my own custom layout sub-classing ViewGroup</li> <li>somewhere early on - possibly in its onCreate()? - create all the children (I know exactly what is needed)</li> <li>in onMeasure() ignore everything the children want, although I suspect I have to call measureChild() to an avoid exception by making sure setMeasuredDimension() is called everywhere, and calculate the layout (sizes, positions) based on the dimensions passed in the width/heightMeasureSpecs</li> <li>in onLayout() just tell all the children how it is going to be ("you are here and this big")</li> <li>since I am not interested in what the children want sizewise, just absorb any layoutRequest() callback and do nothing in it</li> </ul> <p>However, this does seem conceptually to go against how Android thinks layouts should be done - but it is what I need.</p> <p>So my question is - is it a viable scheme?</p>
    singulars
    1. This table or related slice is empty.
    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