Place view inside FrameLayout in Android

前端 未结 5 1304
再見小時候
再見小時候 2020-12-31 17:41

I want to add a view inside a FrameLayout programmatically and to place it in a specific point within the layout with a specific width and height. Does FrameLayout support t

5条回答
  •  悲哀的现实
    2020-12-31 18:00

    From the link Quinn1000 provided:

    You can add multiple children to a FrameLayout, but all children are pegged to the top left of the screen.

    This means you can't put your View at a specific point inside the FrameLayout (except you want it to be at the top left corner :-)).

    If you need the absolute positioning of the View, try the AbsoluteLayout:

    A layout that lets you specify exact locations (x/y coordinates) of its children. Absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning.

    As for setting the width and height of the View, also like Quinn1000 said, you supply the v.setLayoutParams() method a LayoutParams object, depending on the container you chose (AbsoluteLayout, LinearLayout, etc.)

提交回复
热议问题