我的代码没有给我预期的设计
我想制作提要屏幕,这是每个帖子项目的我想要实现的目标。 这是我目前拥有的。我认为这可以完成工作。我是否在某个地方犯了错误,或者我需要在样式中添加其他内容?我在设计上遇到了困难,并认为这足以构建组件。例如,我期望图像是顶部元素,但不知何故它位于中间......另外,当我遇到此类问题时,如何应对它们,有什么建议吗?
<View style={styles.wrapper}>
<Opacity onPress={props.onPostSelect}>
<View style={{ ...styles.postContainer, ...props.style }}>
{/* thumbnail */}
<View style={styles.thumbnailContainer}>
<Image
resizeMode="contain"
source={{ uri: props.item.thumbnailURL }}
style={styles.thumbnail}
/>
</View>
{/* thumbnail end*/}
{/* info container */}
<View style={styles.infoContainer}>
<View style={styles.postDetailsContainer}>
{/* //TITLE */}
<View style={styles.title}>
<Text style={styles.text} numberOfLines={1}>
{props.item.title}
</Text>
</View>
{/* //TITLE end*/}
{/* LIKES/VIEWS */}
<View style={styles.likesAndViewsContainer}>
<Text style={styles.text}>{props.item.views} views | </Text>
{/* LIKES */}
<View style={styles.likesContainer}>
<MaterialIcons name="thumb-up" color="white" size={18} />
<Text style={styles.text}> {props.item.likes} </Text>
</View>
</View>
</View>
</View>
</View>
</Opacity>
</View>
风格:
const styles = StyleSheet.create({
postContainer: {
justifyContent: "center",
borderWidth: 7,
borderColor: "brown",
borderRadius: 2,
backgroundColor: "pink",
marginHorizontal: 5,
height: "95%",
overflow: "hidden",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
},
wrapper: {
flex: 1,
flexGrow: 1,
height: 500,
width: "100%",
backgroundColor: Colors.secondaryColors.lightGray,
overflow: "hidden",
},
title: {
flexDirection: "column",
color: "white",
height: "80%",
},
likesAndViewsContainer: {
flexDirection: "row",
justifyContent: "flex-start",
overflow: "hidden",
},
text: {color:black},
likesContainer: {
flexDirection: "row",
},
thumbnail: {
flex: 1,
width: 100,
height: "100%",
position: "absolute",
},
thumbnailContainer: {
flex: 1,
height: "100%",
width: "100%",
marginVertical: 10,
position: "absolute",
right: 10,
left: 10,
},
infoContainer: {
flexDirection: "row",
},
postDetailsContainer: {
color: "white",
fontSize: 16,
flexDirection: "column",
},
});
I want to make feed screen and this is what i want to achieve for every post item.
This is what i have currently . I thought this will do the work. Am I making a mistake somewhere or I need to add someting else to the styles? I struggle with design and thought this will be enough to structure the components. For example, I expected the image to be the top element but somehow it is in the middle... Also, when I have such problems, how to cope with them, any tips?
<View style={styles.wrapper}>
<Opacity onPress={props.onPostSelect}>
<View style={{ ...styles.postContainer, ...props.style }}>
{/* thumbnail */}
<View style={styles.thumbnailContainer}>
<Image
resizeMode="contain"
source={{ uri: props.item.thumbnailURL }}
style={styles.thumbnail}
/>
</View>
{/* thumbnail end*/}
{/* info container */}
<View style={styles.infoContainer}>
<View style={styles.postDetailsContainer}>
{/* //TITLE */}
<View style={styles.title}>
<Text style={styles.text} numberOfLines={1}>
{props.item.title}
</Text>
</View>
{/* //TITLE end*/}
{/* LIKES/VIEWS */}
<View style={styles.likesAndViewsContainer}>
<Text style={styles.text}>{props.item.views} views | </Text>
{/* LIKES */}
<View style={styles.likesContainer}>
<MaterialIcons name="thumb-up" color="white" size={18} />
<Text style={styles.text}> {props.item.likes} </Text>
</View>
</View>
</View>
</View>
</View>
</Opacity>
</View>
the styles :
const styles = StyleSheet.create({
postContainer: {
justifyContent: "center",
borderWidth: 7,
borderColor: "brown",
borderRadius: 2,
backgroundColor: "pink",
marginHorizontal: 5,
height: "95%",
overflow: "hidden",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
},
wrapper: {
flex: 1,
flexGrow: 1,
height: 500,
width: "100%",
backgroundColor: Colors.secondaryColors.lightGray,
overflow: "hidden",
},
title: {
flexDirection: "column",
color: "white",
height: "80%",
},
likesAndViewsContainer: {
flexDirection: "row",
justifyContent: "flex-start",
overflow: "hidden",
},
text: {color:black},
likesContainer: {
flexDirection: "row",
},
thumbnail: {
flex: 1,
width: 100,
height: "100%",
position: "absolute",
},
thumbnailContainer: {
flex: 1,
height: "100%",
width: "100%",
marginVertical: 10,
position: "absolute",
right: 10,
left: 10,
},
infoContainer: {
flexDirection: "row",
},
postDetailsContainer: {
color: "white",
fontSize: 16,
flexDirection: "column",
},
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这与您的
position:'absolute'
和flex:1
有关。我已经把它清理了一下,请告诉我,这是否是您想要的
样式:
i think there's something to do with your
position:'absolute'
andflex:1
.I've cleaned it up a bit, and do tell me, if this is what you're going for
the styles: