gpt4 book ai didi

react-native - 在图像的顶角放置一个 'x',用于删除(React Native)

转载 作者:行者123 更新时间:2023-12-04 00:26:46 26 4
gpt4 key购买 nike

当方向改变时,然后在图像的顶角使用“x”进行删除。
我可以将垃圾桶图标和位置(img)的名称放在 img 旁边。学习如何放置'x'会很好......
加上(也许)另一个顶角的地方名称。
谢谢

...
class PlaceDetail extends Component {
state = {

viewMode: Dimensions.get('window').height > 500 ? 'portrait' : 'landscape'
}

constructor(props) {
super(props);
Dimensions.addEventListener('change', this.updateStyles )
}

componentWillUnmount() {
Dimensions.removeEventListener('change', this.updateStyles )
}
updateStyles = (dims) => {
this.setState({
viewMode: dims.window.height > 500 ? 'portrait' : 'landscape'
})
}
render(){
return (
<View style={styles.container}>
<View style={this.state.viewMode === 'landscape' ?
styles.viewImageLandScape : null } >
<Image
source={this.props.selectedPlace.image}
style={
this.state.viewMode === 'portrait' ?
styles.placeImagePortrait :
styles.placeImageLanscape }/>
<Text style={styles.placeName}>{this.props.selectedPlace.name}</Text>
</View>
<View>
<TouchableOpacity onPress={this.placeDeleteHandler}>
<View style={styles.deleteButton}>
<Icon size={30} name={Platform.OS ==='android' ? "md-trash" : "ios-trash"} color="red" />
</View>
</TouchableOpacity>
</View>
</View>
);
}

};

const styles = StyleSheet.create({
container: {
margin: 22
},
placeImagePortrait: {
width: '100%',
height: 200
},
viewImageLandScape: {
justifyContent: 'center',
alignItems: 'center',
},
placeImageLanscape: {
width: '50%',
height: 200,
marginTop: 0
},
placeName: {
fontWeight: 'bold',
textAlign: 'center',
fontSize: 28
},
deleteButton: {
alignItems: 'center'
}
});

所以这是带有名称和图像下方删除图标的代码,但在一行中:
 class PlaceDetail extends Component {
state = {
viewMode: Dimensions.get('window').height > 500 ? 'portrait' : 'landscape'
};

constructor(props) {
super(props);
Dimensions.addEventListener('change', this.updateStyles);
}

componentWillUnmount() {
Dimensions.removeEventListener('change', this.updateStyles);
}

updateStyles = (dims) => {
this.setState({
viewMode: dims.window.height > 500 ? 'portrait' : 'landscape'
});
};

placeDeleteHandler = () => {
// selectedPlace: is props we pushed from FindPlace
this.props.onDeletePlace(this.props.selectedPlace.key);
this.props.navigator.pop();
};

render() {
return (
<View style={styles.container}>
<View style={this.state.viewMode === 'landscape' ? styles.viewImageLandScape : null}>
<Image
source={this.props.selectedPlace.image}
style={
this.state.viewMode === 'portrait' ? styles.placeImagePortrait : styles.placeImageLanscape
}
/>
</View>
<View style={this.state.viewMode === 'landscape' ? styles.nameAndIcon : null}>
<Text style={styles.placeName}>{this.props.selectedPlace.name}</Text>
<TouchableOpacity onPress={this.placeDeleteHandler}>
<View style={styles.deleteButton}>
<Icon size={30} name={Platform.OS === 'android' ? 'md-trash' : 'ios-trash'} color="red" />
</View>
</TouchableOpacity>
</View>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
margin: 22
},
nameAndIcon: {
flexDirection: 'row',
justifyContent: 'space-evenly'
},
placeImagePortrait: {
width: '100%',
height: 200
},
viewImageLandScape: {
justifyContent: 'center',
alignItems: 'center'
},
placeImageLanscape: {
width: '50%',
height: 200
},
placeName: {
fontWeight: 'bold',
textAlign: 'center',
fontSize: 28
},
deleteButton: {
alignItems: 'center'
}
});

最佳答案

使用 ImageBackground而不是 Image :


<ImageBackground source={require('YOUR_MAIN_IMAGE')} style={{height: 100, width: 200}}>
<TouchableHighlight
onPress={()=> your_function()}
>
<Image source={require('YOUR_ICON_PATH')} style={{height: 40, width: 40,margin:15}}/>
</TouchableHighlight>

</ImageBackground>

您可以使用 <Text> X </Text> 而不是图标图像

关于react-native - 在图像的顶角放置一个 'x',用于删除(React Native),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56036113/

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