两种颜色的背景 - React Native [英] Background with two colors - React Native

查看:73
本文介绍了两种颜色的背景 - React Native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让背景有两种颜色,如下所示:

离题

我还是不明白为什么人们不喜欢这样的问题.是的,没有发布代码,但这并不意味着他没有尝试任何东西.也许他做了,但他尝试过的方法都没有接近答案,那他为什么要把代码贴在这里,让问题变得冗长,只是为了证明他确实尝试过?而且,即使他没有尝试太多,也许是因为他不知道该尝试什么,这不是可能吗?

有很多问题没有发布任何代码,但得到了数百个赞成票,例如如何在 JavaScript 中从数组中删除元素?".真的吗?老实说,我认为如果您甚至阅读文档并尝试过一些方法,例如 .splice.reduce.unshift,您就会想到无需在 SO 上询问即可.这些问题之所以流行,是因为它们让很多初学者(包括我)的生活变得更轻松,而不是因为这些问题表明问这个问题的人付出了很大的努力.从这个意义上说,这个问题当然是一个很好的问题.(但也许他应该更改问题的标题以使其更具体,因为当他们使用它时会对其他人有益)

Is there a way to have a background with two colors as follows: Two colors I tried expos Linear Gradient, but that's Gradient. I'm not sure how to put two colors in the main View tag as background ? Any suggestions?

解决方案

If the dimensions of the view doesn't get you anywhere, try to manipulate its borders, for example, try this code:

import React, { Component } from 'react'
import { View, Dimensions } from 'react-native'

const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window')

class App extends Component {
    render() {
        return (
            <View style={{ flex: 1 }}>
                <View
                    width: SCREEN_WIDTH,
                    height: 0,
                    borderTopColor: "blue",
                    borderTopWidth: SCREEN_HEIGHT / 2,
                    borderRightWidth: SCREEN_WIDTH,
                    borderRightColor: 'transparent'
                />
            </View>
        )
    }
}

export default App

And it gives you:

Off Topic

I still don't understand why people dislike questions like this. Yes there's no code posted, but it doesn't mean he didn't try anything. Maybe he did, but none of the methods he tried was anywhere near the answer, then why should he post the code up here to make the question lengthy, just to prove that he did try? And, even if he didn't try much, maybe it's because he had no clue what to try, isn't that a possibility?

There are many questions without any code posted but got hundreds of upvotes, such as "How to remove an element from an array in JavaScript?". Really? I honestly think if you even read the documentation and tried some methods such as .splice, .reduce, .unshift, you would've figured that out without having to ask it here on SO. Those questions were popular because they made a lot of beginners (including me) lives easier, not because those questions showed that whoever asked it made a great amount of effort. And this question certainly is a good one in that sense. (But maybe he should change the title of the question to make it more specific, because it would benefit others when they goole it)

这篇关于两种颜色的背景 - React Native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆