Android center view in FrameLayout doesn't work

前端 未结 5 1778
梦谈多话
梦谈多话 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:46

    I'd suggest a RelativeLayout instead of a FrameLayout.

    Assuming that you want to have the TextView always below the ImageView I'd use following layout.

    
    
        
        
    
    

    Note that if you set the visibility of an element to gone then the space that element would consume is gone whereas when you use invisible instead the space it'd consume will be preserved.

    If you want to have the TextView on top of the ImageView then simply leave out the android:layout_alignParentTop or set it to false and on the TextView leave out the android:layout_below="@id/imageview" attribute. Like this.

    
    
        
        
    
    

    I hope this is what you were looking for.

提交回复
热议问题