简体   繁体   English

如何使元素始终位于屏幕的右上角

[英]How to make an element to be always in the top right corner of the screen

I am trying to make an element with style={styles.settingsButtonContainer} not to depend on position of other elements on the view, but to be always in the top right corner of the screen.我正在尝试使用style={styles.settingsButtonContainer}制作一个元素,使其不依赖于视图上其他元素的 position,而是始终位于屏幕的右上角。 I am trying in this way:我正在尝试这种方式:

<View style={styles.container}>
  <RCActivityIndicator animating={showActivityIndicator} />
  <RCModal title={alertTitle} visible={alertVisible} onButtonPress={alertOnPress} />
  <ScrollView contentContainerStyle={{ flexGrow: 1, justifyContent: 'center' }}>
    <Text style={styles.title}>Noughts and Crosses</Text>
    <Text style={styles.tip}>Get {winCondition()} in row, column or diagonal</Text>
    <TouchableHighlight underlayColor="#000000" style={[styles.button, styles.newGameButton]} onPress={setInitialFieldState}>
      <Text style={styles.buttonText}>New game</Text>
    </TouchableHighlight>
    <Text style={styles.turnContainer}>Turn: <Text style={[styles.turn, { color: turn === 'X' ? '#2E86C1' : '#E74C3C'}]}>{turn}</Text></Text>
    <Field state={fieldState} size={fieldSize} winner={winCombination} onCellPress={onCellPress} />
  </ScrollView>
  <View style={styles.settingsButtonContainer}>
    <TouchableHighlight underlayColor={theme.colors.secondary} style={styles.settingsButton} onPress={onSettingsPress}>
      <Image source={require('../img/settings.png')} style={styles.settingsIcon} />
    </TouchableHighlight>
  </View>
</View>

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  title: {
    textAlign: 'center',
    fontSize: 33,
    fontFamily: theme.fonts.primary,
    color: theme.colors.text
  },
  button: {
    alignItems: 'center',
    padding: 5,
    margin: 5,
    marginLeft: 10,
    marginRight: 10,
    borderRadius: 20,
    height: 35,
    justifyContent: 'center'
  },
  newGameButton: {
    backgroundColor: theme.colors.primary,
    paddingLeft: 15,
    paddingRight: 15,
  },
  buttonText: {
    fontSize: 25,
    fontFamily: theme.fonts.primary,
    color: theme.colors.text
  },
  tip: {
    textAlign: 'center',
    fontSize: 25,
    marginLeft: 10,
    marginRight: 10,
    fontFamily: theme.fonts.primary,
    color: theme.colors.text
  },
  turnContainer: {
    textAlign: 'center',
    fontSize: 33,
    fontFamily: theme.fonts.primary,
    color: theme.colors.text,
    marginLeft: 10,
  },
  turn: {
    fontSize: 30,
    fontFamily: theme.fonts.noughtsAndCrosses,
  },
  privacy: {
    textAlign: 'center',
    color: theme.colors.secondaryText,
    fontSize: 15,
    textDecorationLine: "underline",
    marginTop: 20
  },
  settingsButtonContainer: {
    position: 'absolute',
    top: 5,
    right: 5,
    height: 50,
    width: 50,
    alignSelf: 'flex-end',
  },
  settingsButton: {
    height: 50,
    width: 50,
    borderRadius: 25,
  },
  settingsIcon: {
    height: 50,
    width: 50
  },
  settings: {
    marginTop: 30
  },
  buttonsContainer: {
    flexDirection: 'row',
    alignItems: 'center'
  }
});

But it just takes a full row for itself, so the ScrollView doesn't take 100% height.但它本身只占用一整行,因此 ScrollView 不会占用 100% 的高度。 How to make it work?如何让它发挥作用?

try to wrap the settingsButtonContainer尝试包装settingsButtonContainer

and use并使用

settingButtonContainerWrapped: {
alignItem: 'flex-end',
flexDirection : 'row',
},

Use css:使用 css:

.yourelement {
      position: absolute;
      right: 0;
      top: 0;
} 

Actually the issue was in another element, that was on top of the ScrollView - it was RCActivityIndicator who took this place.实际上问题出在另一个元素上,它位于 ScrollView 之上 - 是 RCActivityIndicator 占据了这个位置。 I styled it, and it worked.我设计了它,它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使DIV始终浮在右上角的屏幕上? - How to make a DIV always float on the screen in top right corner? 如何在JS屏幕的右上角插入一个浮动按钮 - How to insert a floating button on top right corner of screen in JS 将元素放置在反应本机的右上角 - Placing element in the top right corner in react native 如何在另一个的右上角显示图像 - How to display an image in the right top corner of another jQuery:即使滚动,如何使对话框保持在右上角? - jQuery: how to make dialogue box stay at top right corner even with scroll? 将d3 SVG元素浮动到右上角CSS - float d3 SVG element to top right corner CSS 将放置按钮放置在位置为相对的元素的右上角 - Place Button at top right corner of an element with position:relative 如何在右下角制作图像作为响应? - How to make an image as a responsive on right bottom corner? 如何使浏览器窗口不可最小化,使其始终位于顶部并通过必要的任何方式将其置于操作系统的一角(javascript / html / C#)? - How to make browser window not minimizable, always on top and have it on a corner of the OS by any means necessary(javascript/html/C#)? 如何将DataTables按钮放在浏览器的右上角? - How to position the DataTables button up to the top right corner of the browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM