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, ...
随机推荐
- 自制mysql的rpm包
MySQL安装一般使用RPM或者源码安装的方式.RPM安装的优点是快速,方便.缺点是不能自定义安装目录.如果需要调整数据文件和日志文件的存放位置,还需要进行一些手动调整.源码安装的优点是可以自定义安装 ...
- linux消息队列应用编程
消息队列: 消息队列提供了一个从一个进程向另外一个进程发送一块数据的方法 每个数据块都被认为是有一个类型,接收者进程接收的数据块可以有不同的类型值 消息队列也有管道一样的不足,就是每个消息的 ...
- MySQL—记录的增删改查操作
1.插入记录: 方法一:INSERT [INTO] tbl_name [(col_name,···)] {VALUES|VALUE} ({expr |DEFAULT},···),(···),··· 例 ...
- Apache Kafka之设计
转自: http://blog.csdn.net/kevin_hx001/article/details/9413565 http://kafka.apache.org/design.h ...
- maven项目中使用redis集群报错: java.lang.NumberFormatException: For input string: "7006@17006"
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [redis.client ...
- 【error】git clone: SSL certificate problem: unable to get local issuer certificate
报错: $ git clone https://github.XXX.git Cloning into 'XXX'... fatal: unable to access 'https://github ...
- 几种创建XMLHttpRequest对象的方法
XMLHttpRequest对象,也就是Ajax交互的核心对象. 这里列举三种创建Ajax对象的方法. 第一种: <!DOCTYPE html> <html> <head ...
- Android -- 网络图片查看器,网络html查看器, 消息机制, 消息队列,线程间通讯
1. 原理图 2. 示例代码 (网络图片查看器) (1) HttpURLConnection (2) SmartImageView (开源框架:https://github.com/loopj/an ...
- Fedora安装opengl
Fedora和Ubuntu下安装OpenGL开发环境配置(我整理的)OpenGL开发库的详细介绍fedora23 安装OpenGL 开发OpenGL工程需要3个库文件和对应的头文件:libglut.s ...
- android AVD启动失败原因之一
在mac上安装好Android SDK.AVD及相关的组件之后,手动创建了一个安卓模拟器后,通过actions启动,会弹出一个提示窗口,然后就闪退,也没有报错什么的,在网上搜了半天AVD启动失败的问题 ...