我构建了反应本机应用程序,并与 scrollView 一起使用带有水平文本列表的标题。问题是滚动视图的高度占屏幕大小的一半。即使将其宣布为一种风格,它仍然保持原样。
带有滚动视图的屏幕
<View style={Style.container} >
{this.props.ExtendedNavigationStore.HeaderTitle ? <BackHeader header={this.props.ExtendedNavigationStore.HeaderTitle} onPressBack={this.goBack} /> : <Header openDrawer={this.openDrawer} />}
<ScrollView contentContainerStyle={{flexGrow:1}} style={Style.scrollableView} horizontal showsHorizontalScrollIndicator={false}>
{this.renderScrollableHeader()}
</ScrollView>
<Routes /> /* stack with dashboard screen */
</View>
</Drawer>
)
}
风格
import {StyleSheet} from 'react-native'
import {calcSize} from '../../utils'
const Styles = StyleSheet.create({
container : {
flex:1,
backgroundColor:"#e9e7e8"
},
scrollableView:{
height: calcSize(40),
backgroundColor: '#000',
},
textCategory:{
fontSize: calcSize(25),
color:'#fff'
},
scrollableButton:{
flex:1,
margin:calcSize(30)
}
})
export default Styles
如您所见,黑色尺寸是滚动视图,我希望它很小。
在路由堆栈到仪表板屏幕中,样式:
const Style = StyleSheet.create({
container: {
backgroundColor: '#9BC53D',
flex: 1,
justifyContent: 'space-around',
alignItems: 'center'
},
text: {
fontSize: 35,
color: 'white',
margin: 10,
backgroundColor: 'transparent'
},
button: {
width: 100,
height: 75,
margin: 20,
borderWidth: 2,
borderColor: "#ecebeb",
justifyContent: "center",
alignItems: "center",
borderRadius: 40
}
})
原文由 Manspof 发布,翻译遵循 CC BY-SA 4.0 许可协议
ScrollView
存在一个限制,其中height
不能直接提供。将
ScrollView
包裹在另一个View
中,并赋予其高度View
。喜欢,
零食样本: https ://snack.expo.io/HkVDBhJoz
EXTRAS:与高度不同,为
ScrollView
提供宽度将正常工作希望这可以帮助。