Percentage width in a RelativeLayout

后端 未结 14 1983
遥遥无期
遥遥无期 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:06

    You are looking for the android:layout_weight attribute. It will allow you to use percentages to define your layout.

    In the following example, the left button uses 70% of the space, and the right button 30%.

    
    
        

    It works the same with any kind of View, you can replace the buttons with some EditText to fit your needs.

    Be sure to set the layout_width to 0dp or your views may not be scaled properly.

    Note that the weight sum doesn't have to equal 1, I just find it easier to read like this. You can set the first weight to 7 and the second to 3 and it will give the same result.

提交回复
热议问题