简体   繁体   English

如何在 React Native 中并排放置在背景顶部和屏幕底部的两个按钮?

[英]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.

相关问题 如何在屏幕底部 position 一个 React Native 元素? - How can I position a React Native element at the bottom of the screen? React Native SafeAreaView 背景颜色 - 如何为屏幕的顶部和底部分配两种不同的背景颜色? - React Native SafeAreaView background color - How to assign two different background color for top and bottom of the screen? 如何并排放置两个下拉菜单? - How can I position two dropdown's side by side? 如何在放置最小化、主页和后退按钮的 REACT NATIVE 中设置屏幕底部的样式? - How can I style bottom section of screen In REACT NATIVE where minimize, home and back buttons are placed? 如何将这些按钮并排放置 - How can I put these buttons side by side 反应本机如何为两个视图并排设置动画 - react native how to animate two views side by side 如何并排制作两个引导按钮? - How do I make two bootstrap buttons side by side? 我可以在 React Native 中使用 webview 作为屏幕背景吗? 如果是,如何? - Can I use webview as a screen background in react native? If yes, How? 如何限制可拖动区域? 它在顶部和左侧起作用,但在右侧和底部不起作用 - How do I limit draggable area? it functions on top and left side, but not on the right side and bottom 如何将背景图像定位到html元素的左上角和右下角? - How can i position a background image to the top left and bottom right of a html element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM