我有一个屏幕,看起来像这样:
return (
<SafeAreaView>
<View style={styles.container}>
<View style={styles.topContainer}>
<View style={styles.searchFieldContainer}>
<FavoritePointInput
textChangeHandler={textChangeHandler}
/>
</View>
<LocationsFound
addressesFound={locations.favAddressesFoundList}
/>
{/* <View style={styles.fixed}> */}
<View style={styles.fieldDescription}>
<Text>Set Location's Name:</Text>
</View>
<View style={styles.searchFieldContainer}>
<Item style={styles.searchField}>
<Input
placeholder="Library"
onChangeText={(text) => setLocationName(text)}
style={styles.searchText}
/>
</Item>
</View>
<View style={styles.buttonContainer}>
<Button style={styles.button}>
<Text>Save Location</Text>
</Button>
</View>
</View>
</View>
{/* </View> */}
</SafeAreaView>
);其Stlyes是这样的:
export const styles = StyleSheet.create({
container: {
height: '100%',
width: '100%',
},
topContainer: {
height: moderateScale(750),
},
topTextContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
marginVertical: moderateScale(15),
height: moderateScale(30),
paddingLeft: moderateScale(30),
paddingRight: moderateScale(30),
},
topMiddleContainer: {
alignItems: 'center',
},
topMiddleText: {
justifyContent: 'center',
paddingBottom: 40,
},
searchFieldContainer: {
alignItems: 'center',
height: moderateScale(120),
},
button: {
width: moderateScale(120),
borderRadius: moderateScale(20),
alignItems: 'center',
alignContent: 'center',
},
buttonContainer: {
flexDirection: 'row',
justifyContent: 'center',
},
searchField: {
width: moderateScale(300, 0.3),
height: verticalScale(40),
marginVertical: moderateScale(3),
borderRadius: verticalScale(10),
},
fieldDescription: {
alignItems: 'center',
},
fixed: {
position: 'absolute',
}
});当我在第一个输入字段中编写内容时,我会通过LocationsFound组件获得搜索结果。这会扰乱整个样式,并将第二个输入字段向下推。我希望它只是简单地重叠并出现在第二个字段的顶部,直到它们中的一个被选中。这有可能吗?


编辑:

发布于 2020-07-09 22:55:25
从代码中看,<LocationsFound>是您的下拉列表。您需要设置此组件的样式并为其提供绝对位置,以便将其从UI的正常定位流中移除。请注意,您将绝对作品定位为相对于其最近定位的祖先,因此您还需要相对定位其父级。
在你的标记中。
<LocationsFound
styles={styles.dropdown}
addressesFound={locations.favAddressesFoundList}
/>在你的风格中
searchFieldContainer {
position: relative,
// other attributes
}
dropdown {
position: absolute,
// adjust top and left according to your situation e.g. 10px
top: 0;
left: 0;
}https://stackoverflow.com/questions/62817333
复制相似问题