Percentage width in a RelativeLayout

后端 未结 14 1976
遥遥无期
遥遥无期 2020-11-22 13:54

I am working on a form layout for a Login Activity in my Android App. The image below is how I want it to look like:

14条回答
  •  孤城傲影
    2020-11-22 14:11

    Since PercentRelativeLayout was deprecated in 26.0.0 and nested layouts like LinearLayout inside RelativeLayout have a negative impact on performance (Understanding the performance benefits of ConstraintLayout) the best option for you to achieve percentage width is to replace your RelativeLayout with ConstraintLayout.

    This can be solved in two ways.

    SOLUTION #1 Using guidelines with percentage offset

    
    
        
    
        
    
        
    
        
    
        
    
    
    

    SOLUTION #2 Using chain with weighted width for EditText

    
    
        
    
        
    
        
    
        
    
    
    

    In both cases, you get something like this

提交回复
热议问题