[英]How can I position two buttons on top of the background side by side and at the bottom of the screen in React Native?
I have a container with a position of relative
and an inner </View>
element with a position of absolute
so the buttons sit on top of the video screen in the background.我有一个具有
relative
位置的容器和一个具有absolute
位置的内部</View>
元素,因此按钮位于背景中的视频屏幕顶部。
When I give the latter its property of absolute
, it no longer stays at the bottom of the screen, but I need to give it this so it stays 'on top' of the image behind it.当我给后者它的
absolute
属性时,它不再停留在屏幕的底部,但我需要给它这个,以便它保持在它后面的图像的“顶部”。
Here are screenshots of before and after the inner element position on absolute
:以下是
absolute
内部元素位置前后的屏幕截图:
Here's my code including the absolute
property:这是我的代码,包括
absolute
属性:
if (props.stream) {
return (
<>
<TouchableWithoutFeedback onPress={handleScreenPress}>
<View style={styles.videoViewWrapper}>
<RTCView style={styles.android} streamURL={props.stream.toURL()} />
<CountDown time={time} />
{/* {showButtons && */}
<View style={{
// position: 'absolute',
}}>
<Button
icon="phone"
mode="contained"
style={{ width: 200, margin: 10 }}
onPress={handleEndCall}
>
End Call
</Button>
<Button
icon="phone"
mode="contained"
style={{ width: 200, margin: 10 }}
onPress={handleSpeakerSwitch}
>
Speaker
</Button>
</View>
{/* } */}
</View>
</TouchableWithoutFeedback>
</>
);
}
return (<> <Loader title="Connecting Your Call.." /> </>)
}
const styles = StyleSheet.create({
videoViewWrapper: {
flex: 1,
overflow: 'hidden'
},
android: {
flex: 1,
position: 'relative',
backgroundColor: 'black'
}
})
export default VideoCall;
I am seeking some tips as to how I could align the two buttons side by side at the bottom and on top of the image behind it, as I'm struggling.我正在寻求一些技巧,以了解如何在图像后面的底部和顶部并排对齐两个按钮,因为我正在挣扎。
If you want to achieve something like this, then see the code :如果你想实现这样的东西,然后看代码:
Check code :检查代码:
export default class App extends React.Component {
render() {
return (
<View style={{flex:1}}>
<View style={{flex:1, flexDirection:'row', alignItems:'flex-end',}}>
<TouchableOpacity
style={{width:'40%' , backgroundColor:'blue' ,marginHorizontal:10}}
>
<Text style={{color:'white',alignSelf:'center', padding:5}}>End Call</Text>
</TouchableOpacity>
<TouchableOpacity
style={{width:'40%', backgroundColor:'blue',marginHorizontal:10}}
>
<Text style={{color:'white',alignSelf:'center', padding:5}}>Pick Call</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
check the link : expo snack检查链接:世博小吃
Hope it helps .feel free for doubts希望它有帮助。不要怀疑
Either you can give them separate positioning, top and left for the first, and top and right for the second button, or put them in a view and set flexDirection of the view to row so they could stay side by side.您可以给它们单独的定位,第一个按钮的顶部和左侧,第二个按钮的顶部和右侧,或者将它们放在视图中并将视图的 flexDirection 设置为行,以便它们可以并排放置。 I have a card object and two buttons on top of it, and it works that way.
我有一个卡片对象和它上面的两个按钮,它就是这样工作的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.