android - React Native - 位置 "absolute"在 Android 中不工作

标签 android react-native

不知何故 position: 'absolute' 在 Android 中不工作。它适用于 iOS,但在 Android 中它不呈现。有人知道如何在 Android 设备上设置 position: "absolute"吗?

Button: {
  position: "absolute",
  right: 0,
  top: 0,
  borderRadius: 4,
  borderWidth: 2,
  width: 100,
  height: 40,
  borderColor: 'red',
  backgroundColor: "rgb(72, 120, 166)",
}

最佳答案

将 Button 包装在 View 中适用于 Android 和 iOS:

import React, { Component } from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.buttonView}>
        <Button style={styles.button} title={"Click"}/>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
  },
  buttonView: {
    position: "absolute",
    right: 0,
    top: 0
  },
  button:{
    borderRadius: 4,
    borderWidth: 2,
    width: 100,
    height: 40,
    borderColor: 'red',
    backgroundColor: "rgb(72, 120, 166)",
  }
});

关于android - React Native - 位置 "absolute"在 Android 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51190180/

相关文章:

android - 如何从 Android 中的视频文件中分离音频流比特率?

react-native - React Native Scrollview 中的scrollToEnd

react-native - Metro 服务器未运行且未连接到 React Native 中的应用程序

reactjs - 扩展 React.Component 与 Component

react-native - react native 表 GridView

android -/bin/sh : adb: command not found

android - 如何在android中将drawable设置为ListView

android - 使用 Protocol- L2TP/IPsec android 开源代码以编程方式配置 VPN。

java - 读取 Java 库

android - 什么是Rage Shake API?