React-native学习过程 二 改变图片和文字的排列
2017-04-04 13:21
411 查看
我们首先对React构造函数做出改动
在container样式里添加flexDirection: ‘row’,使得布局变成水平排放
在rightContainer样式里添加flex: 1,使得文字部分与图片部分平分区域
以下是完整代码:
return ( <View style={styles.container}> <Image source={{uri: movie.posters.thumbnail}} style={styles.thumbnail} /> <View style={styles.rightContainer}> <Text style={styles.title}>{movie.title}</Text> <Text style={styles.year}>{movie.year}</Text> </View> </View> );
在container样式里添加flexDirection: ‘row’,使得布局变成水平排放
在rightContainer样式里添加flex: 1,使得文字部分与图片部分平分区域
以下是完整代码:
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ var MOCKED_MOVIES_DATA = [ {title: 'Title', year: '2015', posters: {thumbnail: 'http://img5.imgtn.bdimg.com/it/u=4080105893,4096129906&fm=206&gp=0.jpg/'}}, ]; import React, { Component } from 'react'; import { AppRegistry, Image, StyleSheet, Text, View } from 'react-native'; export default class MyProject extends Component { render() { var movie = MOCKED_MOVIES_DATA[0]; return ( <View style={styles.container}> <Image source={{uri: movie.posters.thumbnail}} style={styles.thumbnail} /> <View style={styles.rightContainer}> <Text style={styles.title}>{movie.title}</Text> <Text style={styles.year}>{movie.year}</Text> </View> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, thumbnail: { width: 53, height: 81, marginLeft:30, }, rightContainer: { flex: 1, }, title: { fontSize: 20, marginBottom: 8, textAlign: 'center', }, year: { textAlign: 'center', }, }); AppRegistry.registerComponent('MyProject', () => MyProject);
相关文章推荐
- React-native学习过程 一 改变文字,添加图片
- React Native 学习笔记十五(图片的使用)
- React-native学习过程 三 通过网络获取数据
- React Native学习笔记之--图片的加载
- React-Native学习过程搜集资料汇总
- React-Native学习之 图片做背景 modal 点击其他区域消失
- React-native学习过程 九 Text组件综合应用
- React-native学习过程 五 登录界面
- ReactNative学习-滑动查看图片第三方组件react-native-swiper
- React-native学习过程 七 flexbox伸缩项目属性
- React-native学习过程 八 组件综合应用
- React Native学习过程1--搭建开发环境
- React-native学习过程 六 flexbox伸缩容器属性
- React-native学习过程 四 ListView
- react native 学习笔记 2016_1223 (环境,箭头函数,state设置,图片使用等)
- iOS学习之——button重写方法改变button中图片文字的位置
- React Native学习过程中遇到的坑
- ReactNative 之state来改变button的背景图片
- 折腾了一早上的C# WPF ListView+Grid 实现图片+文字 自动换行排列 类似Windows资源管理器效果
- Android加载网络图片学习过程