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, ...
随机推荐
- Clonal hematopoiesis of indeterminate potential(意义不明的克隆性造血)-CHIP
意义不明的克隆性造血是指由一个造血干细胞或者其他早期的起始血细胞为了更好的适应环境而发展成一个带有一些基因变异的亚型. 这个亚型带有基因变异一般是非驱动性的,而且该亚型占血细胞的比率跟年龄有很大的相关 ...
- DATETIME与TIMESTAMP
DATETIME与TIMESTAMP都能表达一个完整的日期格式:YYYY-MM-DD HH:MM:SS[.fraction] eg: mysql> create table test(id in ...
- 20145216 史婧瑶《Java程序设计》第6周学习总结
20145216 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入/输出 10.1 InputStream与OutputStream 如果要将数据从来源中取出,可以使用输 ...
- 20145211 《网络渗透》MS08_067安全漏洞
20145211 <网络渗透>MS08_067安全漏洞 一.实验原理 ms08_067是服务器服务中一个秘密报告的漏洞,于2008年被发现.攻击者利用靶机默认开放的SMB服务的445端口, ...
- CNN笔记:通俗理解卷积神经网络【转】
本文转载自:https://blog.csdn.net/v_july_v/article/details/51812459 通俗理解卷积神经网络(cs231n与5月dl班课程笔记) 1 前言 2012 ...
- PLMN和PSTN
一.PLMNPLMN公众陆地移动电话网(PLMN) public land mobile network 由政府或它所批准的经营者,为公众提供陆地移动通信业务目的而建立和经营的网路.该网路必须与公众交 ...
- Interleaving String,交叉字符串,动态规划
问题描述: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Give ...
- hiho 1318 非法二进制数 dp
#1318 : 非法二进制数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 如果一个二进制数包含连续的两个1,我们就称这个二进制数是非法的. 小Hi想知道在所有 n 位 ...
- MVVM架构简单使用
版权声明:本文为博主原创文章,未经博主授权不得转载. 项目github地址 https://github.com/zhangjiahuan8888/mvvmDemo/tree/master 开篇 MV ...
- 【Python】 \uxxxx转中文
背景 写Python接口自动化过程中,使用到邮件发送测试结果详情,邮件呈现出来的内容为 \uxxxx ,不是中文 接收到的邮件内容: 成功: 110 失败: 1 失败的用例如下 : [(u'\u752 ...