【发布时间】:2016-04-25 03:42:54
【问题描述】:
所以我在视图顶部有一个水平滚动视图。 ScrollView 包含具有指定宽度的节点。然后我在 ScrollView 的底部有一个边框,就像你在这个屏幕截图中看到的那样:http://i.imgur.com/pOV1JFP.png
如您所见,顶部的 ScrollView 的子节点没有到达边界。但是,如果我将 ScrollView 更改为带有flexDirection: 'row' 的视图,则子节点会很好地填充高度。我尝试更改滚动视图上的一些属性,例如:
- 在
contentContainerStyle上设置padding:0 automaticallyAdjustContentInsets={false}- 直接更改
contentInsets的值
这些似乎都不能解决问题。
滚动视图代码和样式:
var styles = StyleSheet.create({
nav: {
padding: 0,
marginTop: 30,
flex: 1,
borderBottomWidth: 1,
borderColor: '#000000'
}
});
<ScrollView
style={[{width: screen.width}, styles.nav]}
horizontal={true}
showsHorizontalScrollIndicator={true}
automaticallyAdjustContentInsets={false}>
{dayNavItems}
</ScrollView>
子组件(组成 dayNavItems)
const styles = StyleSheet.create({
container: {
paddingLeft: 15,
paddingRight: 15,
width: 50,
justifyContent: 'center'
},
odd: {
backgroundColor: '#ccc'
},
selected: {
backgroundColor: '#39b54a'
},
text: {
fontFamily: 'Optima'
}
});
class DayNavItem extends React.Component {
static propTypes = {
day: React.PropTypes.object.isRequired,
odd: React.PropTypes.bool,
selectDay: React.PropTypes.func.isRequired,
selected: React.PropTypes.bool
};
render() {
const d = new Date(this.props.day.created_at);
const viewStyles = [styles.container];
if (this.props.selected) {
viewStyles.push(styles.selected);
} else if (this.props.odd) {
viewStyles.push(styles.odd);
}
return (
<TouchableOpacity style={viewStyles} onPress={() => this.props.selectDay(this.props.day.uuid)}>
<View>
<Text style={styles.text}>{getMonth(d)}</Text>
<Text style={styles.text}>{d.getDate()}</Text>
</View>
</TouchableOpacity>
);
}
}
【问题讨论】:
-
有什么方法可以显示 ScrollView 和父级的代码和样式?
-
感谢您的代码,现在检查一下..
-
您是否尝试过为容器组件设置高度?我得到了类似你正在工作的东西,但我必须给组件一个高度属性:rnplay.org/apps/QP4sBw
-
我还没试过纳德。我真的不想让滚动视图是 flex 的,滚动视图的兄弟姐妹也是如此。
标签: flexbox react-native