Android center view in FrameLayout doesn't work

前端 未结 5 1719
梦谈多话
梦谈多话 2021-02-04 22:47

I have a FrameLayout in which I have 2 controls: - a custom view which draws a image and some text on it - a textview with a text

I want to center both in the FrameLayo

5条回答
  •  梦谈多话
    2021-02-04 23:37

    Just follow this order

    You can center any number of child in a FrameLayout.

    
        
        
    
    

    So the key is

    adding android:layout_gravity="center"in the child views.

    For example:

    I centered a CustomView and a TextView on a FrameLayout like this

    Code:

    
        
        
    
    

    Result:

提交回复
热议问题