javascript - 为我的 child 创建 React Native 应用程序。!

标签 javascript android ios css react-native

我需要有关我的应用程序图标的帮助。我总是在字符周围出现灰色边框,我想在每个字符后面插入一个自定义背景。我只是迷路了。任何帮助将不胜感激。

这里是 React native 元素的代码。

import React, { Component } from 'react';

import { StyleSheet, Text, View, Image,ImageBackground,button,  
TouchableOpacity} from 'react-native';

export default class App extends Component<{}> {
  render() {
   return (
 <View style={{flex: 1, flexDirection: 'row'}}>
    <TouchableOpacity style={styles.button}>
      <Image source={{uri: 'http://www.pngmart.com/files/2/Spider-Man-Transparent-Background.png'}}
   style={{width: 122, height: 550}} />
    </TouchableOpacity>
    <TouchableOpacity style={styles.button}>
      <Image source={{uri:
      'https://vignette.wikia.nocookie.net/avengers-assemble/images/d/d6/Usa_avengers_skchi_blackwidow_n_6e8100ad.png/revision/latest/scale-to-width-down/449?cb=20170426073401'}}
   style={{width: 122, height: 550}} />
    </TouchableOpacity>
    <TouchableOpacity style={styles.button}>
      <Image source={{uri: 'https://clipart.info/images/ccovers/1516942387Hulk-Png-Cartoon.png'}}
   style={{width: 122, height: 500}} />
    </TouchableOpacity>
    <ImageBackground source={{uri: 'http://www.color-hex.com/palettes/6563.png'}} style={{width: '100', height: '100'}}>
<Text>Inside</Text>
  </ImageBackground>
    </View>
  );
 }
}
///need help with coloring each icon
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'blue',
alignItems: 'bottom',
justifyContent: 'bottom',
  },
  button: {
backgroundColor: '#859a9b',
borderRadius: 150,
padding: 1,
marginBottom: -100,
shadowColor: 'white',
shadowOffset: { width: 10, height: 0 },
shadowRadius: 20,
shadowOpacity: 0.45,
  },
});

最佳答案

首先,请在 stackoverflow 中提供正确的工作代码。
您的代码中存在一些错误。

错误

  1. 您代码中 alignItems 样式的 Prop 无效。没有名为 bottom 的 Prop 。它需要是 alignItems:'flex-end'
  2. 您代码中 justifyContent 中的 Prop 无效。那应该是 justifyContent: 'flex-end'More about layout props


要避免字符周围出现灰色边框,您首先需要获取设备的宽度和高度。

import {Dimensions} from 'react-native'

然后在主类之前创建常量以获取设备宽度和高度。

const width = Dimensions.get('window').width; 
const height = Dimensions.get('window').height;

你需要像这样添加背景图片代码..

  <ImageBackground source={{uri: 'http://www.color-hex.com/palettes/6563.png'}}
    style={{width: width, height: height,flexDirection:'row'}}>
    </ImageBackground>

去除按钮背景色代码backgroundColor: '#859a9b',

完整正确的代码应该是这样的……

import React, { Component } from 'react';

import { StyleSheet, Text, View, Image,ImageBackground,button,  
TouchableOpacity,Dimensions} from 'react-native';

const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;


export default class App extends Component<{}> {
  render() {
   return (
 <View style={{flex: 1, flexDirection: 'row'}}>
 <ImageBackground source={{uri: 'http://www.color-hex.com/palettes/6563.png'}} style={{width: width, height: height,flexDirection:'row'}}>

    <TouchableOpacity style={styles.button}>
      <Image source={{uri: 'http://www.pngmart.com/files/2/Spider-Man-Transparent-Background.png'}}
   style={{width: 122, height: 550}} />
    </TouchableOpacity>
    <TouchableOpacity style={styles.button}>
      <Image source={{uri:
      'https://vignette.wikia.nocookie.net/avengers-assemble/images/d/d6/Usa_avengers_skchi_blackwidow_n_6e8100ad.png/revision/latest/scale-to-width-down/449?cb=20170426073401'}}
   style={{width: 122, height: 550}} />
    </TouchableOpacity>
    <TouchableOpacity style={styles.button}>
      <Image source={{uri: 'https://clipart.info/images/ccovers/1516942387Hulk-Png-Cartoon.png'}}
   style={{width: 122, height: 500}} />
    </TouchableOpacity>


  </ImageBackground>
    </View>
  );
 }
}
///need help with coloring each icon
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'blue',
alignItems: 'flex-end',
justifyContent: 'flex-end',
  },
  button: {
borderRadius: 150,
padding: 1,
marginBottom: -100,
shadowColor: 'white',
shadowOffset: { width: 10, height: 0 },
shadowRadius: 20,
shadowOpacity: 0.45,
  },
});

enter image description here

关于javascript - 为我的 child 创建 React Native 应用程序。!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51834076/

相关文章:

ios - 如何在 swift 中从十六进制值创建 NSData

iOS : Transfer Scroll Gesture on a View to Another

javascript - 用 django 和 sql 实现实时倒计时时钟?

javascript - div 覆盖数组 cont 中的每个 div。 (排序功能错误)

android - 点击admob的广告后游戏会退出

android - NDK 解析结果 : Project settings: Gradle model version=5. 4.1,NDK 版本未知错误

iphone - 配置文件 + 推送通知 + 生产与开发

javascript - 为什么这个星级评级的 javascript/CSS 不起作用?

javascript - 如何在 Javascript 中跟踪局部变量值?

java - 为什么我的通知的公共(public)版本没有显示在锁定屏幕上?