How to center a View inside of an Android Layout?

后端 未结 10 1440
深忆病人
深忆病人 2020-12-07 18:18

I want to put a layout in the center of the screen.

10条回答
  •  死守一世寂寞
    2020-12-07 18:56

    Use ConstraintLayout. Here is an example that will center the view according to the width and height of the parent screen:

    
    
    
        
    
    

    You might need to change your gradle to get the latest version of ConstraintLayout:

    dependencies {
    ...
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    }
    

提交回复
热议问题