我构建反应本机应用程序,我使用scrollView for header与文本列表水平.问题是滚动视图的高度占屏幕的一半大小.即使在宣称它是一种风格之后,它仍然保持原样.
屏幕与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>
)
}
Run Code Online (Sandbox Code Playgroud)
款式
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
Run Code Online (Sandbox Code Playgroud)
正如您所看到的黑色大小是滚动视图,我希望它很小.
在路由堆栈到仪表板屏幕中,样式:
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
}
})
Run Code Online (Sandbox Code Playgroud)
小智 50
flexGrow:0
在ScrollView内部使用样式
<ScrollView style={{ flexGrow:0 }}>
Run Code Online (Sandbox Code Playgroud)
Rav*_*Raj 47
有与现有的限制ScrollView
,其中height
不能被直接提供.
把它包裹ScrollView
在另一个中View
并给它高度View
.
喜欢,
render() {
return (
<View style={styles.container}>
<View style={{height: 80}} >
<ScrollView
horizontal
style={{ backgroundColor: 'blue'}}
>
<Text style={{padding: 24}} >title1</Text>
<Text style={{padding: 24}} >title2</Text>
<Text style={{padding: 24}} >title3</Text>
<Text style={{padding: 24}} >title4</Text>
<Text style={{padding: 24}} >title5</Text>
</ScrollView>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
},
});
Run Code Online (Sandbox Code Playgroud)
小吃样品: https ://snack.expo.io/HkVDBhJoz
EXTRAS:不同于提供宽度的高度可以ScrollView
正常工作
希望这可以帮助.
这对我有用:
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
<View style={{ flexGrow: 1 }}>
...
</View>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22066 次 |
最近记录: |