Android and Layouts

后端 未结 2 1016
南方客
南方客 2021-01-03 09:25

I need to locate text on view:

text \'Some more text\' should be located in bottom|center_horizontal

text \'Short text\' should be located on with align righ

2条回答
  •  猫巷女王i
    2021-01-03 10:00

    Here a couple quick guidelines:

    1. Android Layouts tend to be much more deeply nested than you would normally expect. You often end up with "empty" layouts that just take up space so that other elements lay out correctly.
    2. RelativeLayout is your friend whenever you are aligning text to a particular edge.
    3. Use the padding settings to put text "a little away from" an edge.
    4. Gravity aligns the text within that TextView or button.

    Looking again I your diagram, I reproduced it this way:

    1. Start with a relative layout ('fill_content') that takes up the entire screen.
    2. Put in the "short text" and "some more text" by anchoring to the top and bottom.
    3. Put a zero-width item with the property "centerInParent" for a point in the middle of the screen.
    4. Put the remaining to items above and aligned with that centerpoint.

    Unfortunately, nothing in step 4 worked correctly. Nothing like "layout_below" worked when the referenced item was a centerInParent item. with relative layouts to step 3. Turns out it had to do with failing to fill_content on the top level. Yes, the layouts are tricky, and I wish there was a debugger for them.

    Here's the correct version:

    
    
    
    
      
      
    
     
    

提交回复
热议问题