React-Native基础_4.View组件
View组件 对应ios 的UIView android 中的view
使用要先导入View
import {
View
} from 'react-native';
使用就是View标签,可以添加Style样式,View 可以嵌套View和其他组件
文本组件
Text 的使用需要View 组件去包装一下
<View style={[styles.item ,styles.itemOne]}>
<Text style={styles.itemText}>1</Text>
</View>
Text 组件可以嵌套Text
<Text> <Text>aaa</Text>bbb </Text>
自定义文本组件
声明
class ComText extends React.Component{
render(){
return(
<Text style ={styles.itemText}>
{this.props.children}
</Text>
);
}
}
使用: <ComText>ComText</ComText>
图像组件 Image
<Image style = {styles.image}
source ={{uri:'http://imgsrc.baidu.com/image/c0%3Dshijue1%2C0%2C0%2C294%2C40/sign=32c015eaf6039245b5b8e94ceffdceb7/d788d43f8794a4c28c10040c04f41bd5ad6e39e2.jpg'}}/>
指定source uri 图片路径可以是本地 也可以是网络
背景图片,background 将图片flex:1 当作背景,然后嵌套组件
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
'use strict'
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Image,
View
} from 'react-native';
//import {AppRegistry,} from 'react-native';
//import Day0718 from './componets/Home'
export default class Day0718 extends Component {
render() {
return (
<View style={styles.Container}>
<Image style = {styles.backImage}
source ={{uri:'http://imgsrc.baidu.com/image/c0%3Dshijue1%2C0%2C0%2C294%2C40/sign=32c015eaf6039245b5b8e94ceffdceb7/d788d43f8794a4c28c10040c04f41bd5ad6e39e2.jpg'}}>
<View style={styles.overlay}>
<Text style={styles.overlayHeader}> 小美女,你瞅啥呢</Text>
<Text style={styles.overlaySubHeader}> 小美女</Text>
</View>
</Image>
</View>
);
}
}
const styles = StyleSheet.create({
overlay:{
backgroundColor:'rgba(0,0,0,0.3)',
alignItems:'center'
},
overlayHeader:{
fontSize:33,
fontFamily:'Helvetica Neue',
fontWeight:'200',
color:'#eae7ff',
padding:10
},
overlaySubHeader:{
fontSize:16,
fontFamily:'Helvetica Neue',
fontWeight:'200',
color:'#eae7ff',
padding:10,
paddingTop:0,
},
backImage:{
// alignItems:'center',
flex:1,
//justifyContent:'center',
resizeMode:'cover',
},
image:{
height:200,
width:100,
justifyContent:'center',
},
item:{
backgroundColor:'#fff',
borderWidth:1,
borderColor:'#6435c9',
margin:6,
flex:1,
},
itemOne:{
// alignSelf:'flex-start',
},
itemTwo:{
//alignSelf:'center',
},
itemThree:{
flex:2,
},
itemText:{
fontSize:33,
fontFamily:'Helvetica Neue',
fontWeight:'200',
color:'#6435c9',
padding:30,
},
Container: {
//alignItems:'flex-start',// flex-start 靠在左边显示 center 居中 flex-end 尾部
//
flexDirection:'column',//row column 方向
backgroundColor: '#eae7ff',
flex: 1,
//justifyContent:'center',//center ; 居中 flex-end 位于底部 space-between/space-around屏幕平均分配
},
Text: {
color: '#6435c9',
fontSize: 26,
textAlign: 'center',
fontStyle: 'italic',
letterSpacing: 2,
lineHeight: 33,
fontFamily: 'Helvetica Neue',
fontWeight: '300',
textDecorationLine: 'underline',
textDecorationStyle: 'dashed',
},
});
class ComText extends React.Component{
render(){
return(
<Text style ={styles.itemText}>
{this.props.children}
</Text>
);
}
}
AppRegistry.registerComponent('Day0718', () => Day0718);
注 :View组件(对应Android 中原生的View ,ios 中原生的UIView)
文本视图<Text>
图片视图<Image>
视图组件可以嵌套, 图片指定source uri:‘路径’,可以是本地路径也可以是远程路径
React-Native基础_4.View组件的更多相关文章
- React Native基础&入门教程:初步使用Flexbox布局
在上篇中,笔者分享了部分安装并调试React Native应用过程里的一点经验,如果还没有看过的同学请点击<React Native基础&入门教程:调试React Native应用的一小 ...
- react native基础与入门
react native基础与入门 一.react native 的优点 1.跨平台(一才两用) 2.低投入高回报 (开发成本低.代码复用率高) 3.性能高:拥有独立的js渲染引擎,比传统的h5+ w ...
- React Native 项目常用第三方组件汇总
React Native 项目常用第三方组件汇总 https://www.jianshu.com/p/d9cd9a868764?utm_campaign=maleskine&utm_conte ...
- React Native知识5-Touchable类组件
React Native 没有像web那样可以给元素绑定click事件,前面我们已经知道Text组件有onPress事件,为了给其他组件 也绑定点击事件,React Native提供了3个组件来做这件 ...
- React Native基础&入门教程:调试React Native应用的一小步
React Native(以下简称RN)为传统前端开发者打开了一扇新的大门.其中,使用浏览器的调试工具去Debug移动端的代码,无疑是最吸引开发人员的特性之一. 试想一下,当你在手机屏幕按下一个按钮, ...
- 跨平台框架与React Native基础
跨平台框架 什么是跨平台框架? 这里的多个平台一般是指 iOS 和 Android . 为什么需要跨平台框架? 目前,移动开发技术主要分为原生开发和跨平台开发两种.其中,原生应用是指在某个特定的移动平 ...
- React Native基础&入门教程:以一个To Do List小例子,看props和state
本文由葡萄城技术团队于博客园原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 在上篇中,我们介绍了什么是Flexbox布局,以及如何使用Flexb ...
- React Native基础概念和基础认识
学习地址:https://github.com/vczero/react-native-lesson 当我们初始化一个RN项目的时候主要的是index.ios.js文件和index.android.j ...
- React Native 之 定义的组件 (跨文件使用)
哈哈的~~~今天介绍的是自定义组件 然后去使用这个组件,让这个组件传递这各种文件之间 哈哈 下面开始吧!!!! 我们所要创建的是一个自定义的Button,先创建一个js文件起名为MyButton, ...
随机推荐
- 索引原理-btree索引与hash索引的区别
btree索引与hash索引的区别,之前不清楚,mark一下. Hash索引结构的特殊性,其检索效率非常高,索引的检索可以一次定位,不像B-Tree索引需要从根节点到枝节点,最后才能访问到页节点这样多 ...
- ARTS Week 001
Algorithm Leetcode 1. Two Sum Given an array of integers, return indices of the two numbers such tha ...
- 单调队列:temperature
题目大意:某国进行了连续n天的温度测量,测量存在误差,测量结果是第i天温度在[l_i,r_i]范围内. 求最长的连续的一段,满足该段内可能温度不降. 第一行n下面n行,每行l_i,r_i 1<= ...
- 4.9版本的linux内核中实时时钟芯片pcf85263的驱动源码在哪里
答:drivers/rtc/rtc-pcf85263.c,内核配置选项为 CONFIG_RTC_DRV_PCF85263 Location: -> Device Drivers -> Re ...
- 实现ModelDriver接口的功能(转)
ModelDriver接口 来自com.opensymphony.xwork2.ModelDriven.是xwork-2.1.2-750.jar包的东西. 下面是源码: package com.ope ...
- Windows下才有blat进行命令行邮件发送
1.先下载blat.exe文件,下载地址: https://sourceforge.net/projects/blat/files/ 2.解压后只需要blat.exe即可,进入此文件夹,运行如下脚本进 ...
- git gc内存错误的解决方案
Auto packing the repository for optimum performance. You may alsorun "git gc" manually. Se ...
- TSP - 状态压缩dp
2017-08-11 21:10:21 艾教写的 #include<iostream> #include<cstdio> #include<cstring> #in ...
- Android -- 网络图片查看器,网络html查看器, 消息机制, 消息队列,线程间通讯
1. 原理图 2. 示例代码 (网络图片查看器) (1) HttpURLConnection (2) SmartImageView (开源框架:https://github.com/loopj/an ...
- Struts2框架学习第一章——Struts2概述
本章要点 — Web应用的发展 — Model 1和Model 2 — MVC思想 — MVC模式的优势 — 常用MVC框架及其特征 — Struts 1的基本结构及其存在的问题 — We ...