【问题标题】:how to design semi-circle/oval in react native?如何在本机反应中设计半圆形/椭圆形?
【发布时间】:2020-07-02 11:51:30
【问题描述】:

我是 React Native 的新手。我正在设计要设计半圆形或椭圆形的 UI。我试过了,但输出不符合预期。我们可以在 react native 中使用 canvas 或 svg 吗?

实际:

当前:

代码.js

     <View style={{ flex: 1, flexDirection: 'row' }}>    
          <View style={styles.circleSkyBlue}></View>
          <View style={styles.circleViolet}></View> 
     </View>

code.css

      circleViolet:{
            width: 239,
            height: 134,
          
            borderBottomRightRadius: 50,
            borderBottomLeftRadius: 100, 
            backgroundColor: '#596AB2',
            transform: [
                {scaleX: 1.2}
                ] 
        },
        circleSkyBlue:{
            width: 180,
            height: 84,               
            borderBottomRightRadius: 100,
            borderBottomLeftRadius: 50,
          
            backgroundColor: '#69C0EC',
            transform: [
                {scaleX: 1}
                ] ,
                overflow: 'hidden', 
        },

感谢任何帮助。 提前谢谢你

【问题讨论】:

  • 您可以创建圈子并将其设为positionabsolute。然后将其设置为position

标签: javascript css react-native


【解决方案1】:

我创建了一个小吃,您可以在其中查看示例。这里不用egg,你可以用position来得到你想要的UI。

小吃:https://snack.expo.io/@ashwith00/ovals

代码:

import * as React from 'react';
import { Text, View, StyleSheet, Dimensions } from 'react-native';
import Constants from 'expo-constants';

const {width} = Dimensions.get('window')

const oval1Width = width * 0.5, oval2Width = width * 0.7;
// You can import from local files
import AssetExample from './components/AssetExample';

// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';

export default function App() {
  return (
    <View style={styles.container}>
     <View style={styles.oval1} />
     <View  style={styles.oval2} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  oval1: {
    position: 'absolute',
    width: oval1Width,
    height: oval1Width,
    borderRadius: oval1Width / 2,
    backgroundColor: 'red',
    top: -oval2Width / 3,
    left: -10,
zIndex: 3,
  },
  oval2: {
     position: 'absolute',
    width: oval2Width,
    height: oval2Width,
    borderRadius: oval2Width / 2,
    backgroundColor: 'blue',
    top: -oval2Width / 2.5,
    right: -10,
    zIndex:2
  },
});

【讨论】:

  • 这是完美的。谢谢@Ashwith Saldanha。非常感谢您的回答和即时回复。
  • 我希望红色椭圆应该向上,蓝色椭圆在后面。我该如何实现?
  • 把 zIndex: 2 放在椭圆1 样式中,它会使红色出现
猜你喜欢
  • 2017-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-25
相关资源
最近更新 更多