用React Native里的ScrollView
元件,給ScrollView
直接加了justifyContent
或alignitems
屬性後會報錯。
報錯信息:
ScrollView child layout ([“alignitems”, “justifyContent”]) must be applied through the contentContainerStyle prop
問題原因是scrollView和flatlist之類的元件不支持直接添加這兩個屬性,解決方法是給元件添加contentContainerStyle屬性,這些樣式會應用到一個內層的內容容器上,所有的子視圖都會包裹在內容容器內,在這個屬性後面指定對應的樣式即可: