你可以将两个按钮在React Native中放置在屏幕底部并且并排放在背景上。

huangapple go评论97阅读模式
英文:

How can I position two buttons on top of the background side by side and at the bottom of the screen in React Native?

问题

在容器中,有一个position属性设置为relative,以及一个内部的</View>元素,其position属性设置为absolute,以便按钮位于背景中的视频屏幕之上。

当我给后者设置position属性为absolute时,它不再位于屏幕底部,但我需要这样设置它以保持在图像之上。

以下是内部元素设置为absolute后之前和之后的屏幕截图:

你可以将两个按钮在React Native中放置在屏幕底部并且并排放在背景上。

你可以将两个按钮在React Native中放置在屏幕底部并且并排放在背景上。

这是包括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 have a container with a position of relative and an inner &lt;/View&gt; element with a position of absolute so the buttons sit on top of the video screen in the background.

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.

Here are screenshots of before and after the inner element position on absolute:

你可以将两个按钮在React Native中放置在屏幕底部并且并排放在背景上。

你可以将两个按钮在React Native中放置在屏幕底部并且并排放在背景上。

Here's my code including the absolute property:

if (props.stream) {
    return (
      &lt;&gt;
        &lt;TouchableWithoutFeedback onPress={handleScreenPress}&gt;
          &lt;View style={styles.videoViewWrapper}&gt;
            &lt;RTCView style={styles.android} streamURL={props.stream.toURL()} /&gt;
            &lt;CountDown time={time} /&gt;
            {/* {showButtons &amp;&amp; */}
            &lt;View style={{
              // position: &#39;absolute&#39;,
            }}&gt;
              &lt;Button
                icon=&quot;phone&quot;
                mode=&quot;contained&quot;
                style={{ width: 200, margin: 10 }}
                onPress={handleEndCall}
              &gt;
                End Call
              &lt;/Button&gt;
              &lt;Button
                icon=&quot;phone&quot;
                mode=&quot;contained&quot;
                style={{ width: 200, margin: 10 }}
                onPress={handleSpeakerSwitch}
              &gt;
                Speaker
                &lt;/Button&gt;
            &lt;/View&gt;
            {/* } */}
          &lt;/View&gt;
        &lt;/TouchableWithoutFeedback&gt;
      &lt;/&gt;
    );
  }
  return (&lt;&gt; &lt;Loader title=&quot;Connecting Your Call..&quot; /&gt; &lt;/&gt;)
}

const styles = StyleSheet.create({
  videoViewWrapper: {
    flex: 1,
    overflow: &#39;hidden&#39;
  },
  android: {
    flex: 1,
    position: &#39;relative&#39;,
    backgroundColor: &#39;black&#39;
  }
})

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.

答案1

得分: 2

Here's the translated code:

如果您想实现类似这样的效果请查看以下代码

[![在这里输入图片描述][1]][1]

检查代码

    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}}>结束通话</Text>
                  </TouchableOpacity>
                  <TouchableOpacity
                     
                   style={{width:'40%', backgroundColor:'blue',marginHorizontal:10}}
          
                   
                  >
                   <Text style={{color:'white',alignSelf:'center', padding:5}}>接听通话</Text>
                  </TouchableOpacity>
                  </View>
          </View>
        );
      }
    }

检查链接 [expo snack][2]

希望对您有所帮助有疑问请随意提问

  [1]: https://i.stack.imgur.com/fnMmP.png
  [2]: https://snack.expo.io/B1RYno6JL

Please note that the translation is provided as per your request and only includes the code portion. If you have any doubts, feel free to ask.

英文:

If you want to achieve something like this, then see the code :

你可以将两个按钮在React Native中放置在屏幕底部并且并排放在背景上。

Check code :

export default class App extends React.Component {
render() {
return (
&lt;View style={{flex:1}}&gt;
&lt;View style={{flex:1, flexDirection:&#39;row&#39;, alignItems:&#39;flex-end&#39;,}}&gt;     
&lt;TouchableOpacity
style={{width:&#39;40%&#39; , backgroundColor:&#39;blue&#39; ,marginHorizontal:10}}
&gt;
&lt;Text style={{color:&#39;white&#39;,alignSelf:&#39;center&#39;, padding:5}}&gt;End Call&lt;/Text&gt;
&lt;/TouchableOpacity&gt;
&lt;TouchableOpacity
style={{width:&#39;40%&#39;, backgroundColor:&#39;blue&#39;,marginHorizontal:10}}
&gt;
&lt;Text style={{color:&#39;white&#39;,alignSelf:&#39;center&#39;, padding:5}}&gt;Pick Call&lt;/Text&gt;
&lt;/TouchableOpacity&gt;
&lt;/View&gt;
&lt;/View&gt;
);
}
}

check the link : expo snack

Hope it helps .feel free for doubts

答案2

得分: 0

要么你可以为它们分别设置位置,第一个按钮设置为上和左,第二个按钮设置为上和右,要么将它们放在一个视图中,并将视图的flexDirection属性设置为row,这样它们可以并排放置。我有一个卡片对象,上面有两个按钮,它就是这样工作的。

英文:

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. I have a card object and two buttons on top of it, and it works that way.

huangapple
  • 本文由 发表于 2020年1月4日 00:36:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582127.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定