javascript - 在 react-native 中从 superview 的底部布局一个按钮

标签 javascript ios reactjs react-native

我想像这样在 React Native 中渲染一个按钮:

enter image description here

听到的是我的代码:

    class Test extends Component {
      render() {
        return (
          <View>
            <TouchableHighlight style={{marginBottom:20,height:40,backgroundColor:'blue',justifyContent:'center'}}>
            <Text style={{alignSelf:'center',color:'white'}}>Login</Text>
            </TouchableHighlight>          
          </View>
        );
      }
   }

但是上面提到的渲染结果是:

enter image description here

如何修改我的代码?

最佳答案

在这种情况下使用 position: 'absolute',例如:

loginButton: {
   position:'absolute',
   bottom: 0,
   height:40,
   backgroundColor:'blue',
   justifyContent:'center',
   width: width
 }

渲染应该是:

render() {
   return (
      <View style={styles.loginButton}>
         <TouchableHighlight>
            <Text style={styles.loginButtonText}>Login</Text>
         </TouchableHighlight>          
      </View>
   );
}

这是完整的工作代码:https://rnplay.org/apps/6qMTdA

关于javascript - 在 react-native 中从 superview 的底部布局一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37370630/

相关文章:

javascript - 为什么对象原型(prototype)方法在 oop 中没有调用者,这与过程式编程不同

javascript - 是否可以将 localStorage 项目保持私有(private)或隐藏?

javascript - 理解 Redux 的 Reducer 存储状态

javascript - 将值保存到组件状态的问题

javascript 如何在创建对象后将新对象添加到对象中

javascript - 在 Masonry 初始化之前停止显示项目

ios - Firebase iOS - 键/值对并未从数据库中物理删除

ios - 在 Swift 中观察 ObjC 类的属性

ios - appdelegate.m 中 View Controller 的 ivar

reactjs - 以下模块无法热更新 : (Full reload needed)