RelativeLayout設定wrap_content無效,

來源:互聯網
上載者:User

RelativeLayout設定wrap_content無效,

尊重勞動成果,轉載請標明出處:http://www.cnblogs.com/tangZH/p/8419053.html 

 

在做項目的過程中,遇到了一個奇怪的現象,我設定RelativeLayout為的寬度為wrap_content,而且RelativeLayout裡面的組件也設定了固定大小,可是RelativeLayout寬度大小還是會鋪滿整個螢幕。 

 

為啥???一臉悶逼

百度之後發現,官方文檔有解釋:

A Layout where the positions of the children can be described in relation to each other or to the parent.Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM.

 

它的意思大概是說:不能在RelativeLayout的大小和子級的位置之間存在循環相依性關係。 例如,不能將RelativeLayout的高度設定為WRAP_CONTENT,將子設定為ALIGN_PARENT_BOTTOM。

 

就我遇到的兩種情況而言是這樣的:

1、設定RelativeLayout的寬度為wrap_content,子組件設定為

android:layout_alignParentEnd="true"

於是出現了RelativeLayout寬度鋪滿螢幕的現象

 

2、設定RelativeLayout的高度為wrap_content,子組件設定為

ALIGN_PARENT_BOTTOM

於是出現了RelativeLayout的高度鋪滿螢幕的現象

 

最終,我還是乖乖改為LinearLayout布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.