javascript - 如何在 React Native 上设置 Slider 的样式
问题描述
我有一个特定的滑块。我该如何设计它们?我使用react-native-slider。这是我的代码(我从这个例子修改了代码):
render() {
const sliderStyle = {
sliderDummy: {
width: 200,
height: 80,
position: 'absolute',
},
sliderReal: {
backgroundColor: colors.primary,
width: (this.state.slideValue / 50) * 200,
height: 80,
borderBottomRightRadius: 100,
borderTopRightRadius: 100
}
}
return (
<View style={styles.container}>
<View style={{overflow: 'hidden'}}>
<View style={{flexDirection: 'row', position: 'absolute'}}>
<View style={sliderStyle.sliderDummy}></View>
<View style={sliderStyle.sliderReal}></View>
</View>
<Slider
style={{width: 200, height: 80}}
minimumValue={0}
maximumValue={50}
value={this.state.slideValue}
onValueChange={(value)=> this.setState({ slideValue: value}) }
maximumTrackTintColor='transparent'
minimumTrackTintColor='transparent'
thumbStyle={styles.thumb}
/>
<Text>{this.state.slideValue}</Text>
</View>
</View>
);
}
}
当我向右滑动时,我在轨道中间有圆角:
但我需要这样的东西:
我的错误在哪里?谢谢。
解决方案
我比预期更容易解决这个问题。我刚刚设置了 trackStyle(react-native-slider) 这就像一个魅力。但现在我有另一个问题,如何获得像“斑马”一样的滑块样式轨道。
render() {
return (
<View style={styles.container}>
<Slider
style={{width: 150, height: 80}}
minimumValue={this.state.min}
maximumValue={this.state.max}
value={this.state.min}
onValueChange={(value)=> this.setState({ slideValue: value}) }
maximumTrackTintColor='transparent'
minimumTrackTintColor={colors.primary}
thumbStyle={styles.thumb}
trackStyle={styles.track}
step={1}
/>
<Text>{this.state.slideValue}</Text>
<Text>min {this.state.min}</Text>
<Text>max {this.state.max}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
thumb: {
width: 50,
height: 80,
backgroundColor: colors.primary,
borderBottomRightRadius: 100,
borderTopRightRadius: 100,
},
track:{
height: 80,
borderBottomRightRadius: 20,
borderTopRightRadius: 20,
}
});
推荐阅读
- python - 为什么我会收到 CommandError:App 'appname' 在 heroku 中没有迁移?
- python-3.x - 加入多个熊猫数据框
- redis - 使用 RedisGears 对接收 pubsub 消息进行计算
- r - 识别和替换公式中的参数,如 R 中的字符串
- python - Python安装pyPdf错误'utf-8'编解码器无法解码位置64的字节0x88
- excel - 在 excel 中从 CustomXmlPart 遍历 XML 时遇到问题
- scipy - 如何合并边界条件并从 scipy.interpolate.Bspline.basis_element 构建基函数,包括边界条件?
- javascript - Javascript在引号中加粗文本字符串
- javascript - 滚动条的禁用区域
- postgresql - 与 Azure VM 上的 PostgreSQL 数据库层失去连接