gpt4 book ai didi

javascript - 如何在 React Native 上设置 Slider 的样式

转载 作者:行者123 更新时间:2023-12-05 00:33:16 24 4
gpt4 key购买 nike

我有一个特定的 slider 。我该如何设计它们?我用 react-native-slider .这是我的代码(我从 example 修改了代码):

    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>
);
}
}

当我向右滑动时,我在轨道中间有圆 Angular :

enter image description here

但我需要这样的东西:

enter image description here

我的错误在哪里?谢谢。

最佳答案

我比预期更容易解决这个问题。我刚刚设置了 trackStyle(react-native-slider) 这就像一个魅力。但现在我有另一个问题,如何获得像“斑马”一样的 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,
}
});

enter image description here

关于javascript - 如何在 React Native 上设置 Slider 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54749795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com