【发布时间】:2021-01-29 17:50:00
【问题描述】:
有没有办法像在 HTML 中使用 React Native 一样创建下拉导航菜单,其中下拉部分绝对位于菜单下方内容的顶部?
在没有绝对定位的情况下,下拉菜单的父元素(下图,蓝色背景)会增加其高度,而其他内容在下拉菜单下方。
当我在下拉列表中使用绝对位置时,它在第 1 项之上而不是在它之下,因为 React Natives 相对于父项定位绝对位置。
我的代码:
<View style={{ flex: 1 }}>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'baseline', backgroundColor: '#3763a4'}}>
<View style={{ backgroundColor: '#FF0000', flex: 1 }}>
<View style={{ padding: 10 }}>
<Text style={{ color: '#FFFFFF' }}>Item 1</Text>
</View>
<View style={{ padding: 10 }}>
<Text style={{ color: '#FFFFFF' }}>Item 1.1</Text>
<Text style={{ color: '#FFFFFF' }}>Item 1.2</Text>
</View>
</View>
<View style={{ padding: 10, backgroundColor: '#FF0000', flex: 1 }}><Text style={{ color: '#FFFFFF' }}>Item 2</Text></View>
<View style={{ padding: 10, backgroundColor: '#FF0000', flex: 1 }}><Text style={{ color: '#FFFFFF' }}>Item 3</Text></View>
</View>
<WebView
source={myHtml}
/>
</View>
它的样子:
Webview 在此下方。相反,下拉菜单应位于 Web 视图的顶部。
我希望我的解释足够清楚。此图像和链接显示 HTML 导航菜单:https://www.w3schools.com/howto/howto_css_dropdown_navbar.asp
【问题讨论】:
-
你可以查看github代码akveo.github.io/react-native-ui-kitten/docs/components/…或者选择你想要的
标签: react-native drop-down-menu