【问题标题】:My hamburger menu lines are not aligned what to do我的汉堡菜单行不对齐怎么办
【发布时间】:2019-04-15 23:13:42
【问题描述】:

我的汉堡没有在屏幕上对齐

我已经访问了不同的样式方法,例如 alignItems,但仍然没有结果。关于边距定位,我不能再向左将每条线(全部 3 条)分开约 2 px。 主要问题是每行的水平对齐。

有人可以帮忙吗?

import React from 'react';
import {AppRegistry, StyleSheet, View} from "react-native" ;




export default class MenuButton extends React.Component {
    render() {
        return(
        <View style={menuIcon.mainLine}>

         <View style={menuIcon.line2}>
          <View style={menuIcon.line3}>
            </View>
             </View>
                 </View>
        ) 
    }
}

const menuIcon = StyleSheet.create({
   mainLine: {
        flex: 1,
backgroundColor : 'rgba(255, 255, 255, 1)',
top  : 4,
height              : 6.5,
width               : 35,
  position            : 'absolute',
  marginTop              : 40,
  marginLeft             : 25,
 alignItems             : "stretch",
  left                : 0,
  right                : 0,
   borderRadius       : 20,
  borderStyle        : 'solid',
  borderWidth        : 1,
  borderColor        : 'rgba(205, 205, 205, 1)'
  },
    line2: {
        flex: 1,
backgroundColor : 'rgba(255, 255, 255, 1)',
top  : 7,
height              : 6.5,
width               : 35,
  position            : 'absolute',
  marginTop              : 0,
  marginLeft             : 0,

  left                : 0,
  right                : 0,
   borderRadius       : 20,
  borderStyle        : 'solid',
  borderWidth        : 1,
  borderColor        : 'rgba(205, 205, 205, 1)'
  },
   line3: {
        flex: 1,
backgroundColor : 'rgba(255, 255, 255, 1)',
top  : 7,
height              : 6.5,
width               : 35,
  position            : 'absolute',
  marginTop              : 0,
  marginLeft             : 0,

  left                : 0,
  right                : 0,
   borderRadius       : 20,
  borderStyle        : 'solid',
  borderWidth        : 1,
  borderColor        : 'rgba(205, 205, 205, 1)'
  }
  })

AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);

【问题讨论】:

    标签: css iphone react-native frontend hamburger-menu


    【解决方案1】:

    我建议为此使用react-native-vector-icons

    但如果您想自己实现它,请在您的渲染函数中进行此更改

    render() {
      return(
        <View>
          <View style={menuIcon.mainLine}></View>
          <View style={menuIcon.line2}></View>
          <View style={menuIcon.line3}></View>
        </View>
      ) 
    }
    

    【讨论】:

      【解决方案2】:

      通常我们不会自己编写汉堡包代码..或任何其他按钮图标。

      我们在视图中使用图标或图像并将 onPress 应用于视图本身

      通过 react-native 我们使用 react-native-vector-icons 库。安装基本使用指南在这里

      https://www.npmjs.com/package/react-native-vector-icons

      【讨论】:

      • 是的,我知道,但是在这种情况下,我设计了图标,所以我想知道如何在导出我的设计 CSS 文件后直接绘制和定位它
      • 首先将所有三行包含在单个视图中,宽度和高度以及 flexDirection = cloumn.. 然后... 在里面写下您的 line1,2,3 并正确对齐它们。
      • 而您正在做的是...构建 flex1 然后在 flex1 内部 ..构建 flex2 ..然后在 flex2 ..构建 flex 3
      • 所以创建一个具有..高度和宽度的容器......然后在容器内,您可以绘制所有三条线......并利用 flex1 的可用空间......具有一些高度
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多