I want to know: What is android:weightSum and layout weight, and how do they work?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Per documentation,
android:weightSumdefines the maximum weight sum, and is calculated as the sum of thelayout_weightof all the children if not specified explicitly.Let’s consider an example with a
LinearLayoutwith horizontal orientation and 3ImageViewsinside it. Now we want theseImageViewsalways to take equal space. To acheive this, you can set thelayout_weightof eachImageViewto 1 and theweightSumwill be calculated to be equal to 3 as shown in the comment.weightSumis useful for having the layout rendered correctly for any device, which will not happen if you set width and height directly.