個人經驗 - Android的RelativeLayout布局的layout_height屬性設定為wrap_content時的坑

來源:互聯網
上載者:User

標籤:android   style   color   使用   ar   strong   sp   on   bs   

Android的RelativeLayout布局的layout_height屬性設定為wrap_content時的坑:

此坑出現的條件:

1.RelativeLayout布局的layout_height屬性設定為wrap_content

2.某“置中View”設定為layout_centerX(layout_centerVertical、layout_centerHorizontal、layout_centerInParent)

3.其它View相對於“置中View”做布局

此時坑出現了:

無論其它View設定了在“置中View”的下方(layout_below、layout_below)、上方(layout_above)、底部對齊(layout_alignBottom)等等,通通無效!

 

填坑方案:

RelativeLayout布局的layout_height屬性設定為match_parent即可!

即使外層有LinearLayout使用layout_weight平分空間,它的match_parent也不會撐大外層LinearLayout的空間的。

當初想設定wrap_content,其實就是怕內部的RelativeLayout設定match_parent後會被撐大而已,實踐證明,多慮了!

個人經驗 - Android的RelativeLayout布局的layout_height屬性設定為wrap_content時的坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.