How to center the elements in ConstraintLayout

后端 未结 6 2025

I am using ConstraintLayout in my application to make applications layout. I am trying to a create a screen wheren one EditText and Button

6条回答
  •  無奈伤痛
    2020-12-07 10:34

    You can center a view as a percentage of the screen size.

    This example uses 50% of width and height:

    
    
        
    
    
    

    This was done using ConstraintLayout version 1.1.3. Don't forget to add it to your dependencies in the gradle, and increase the version if there is a new version out there:

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

提交回复
热议问题