React-Native基础_5.列表视图ListView 网络数据展示
//获取网络数据 并用列表展示 豆瓣Top250 api
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
'use strict'
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Image,
View,
ListView,
} from 'react-native';
//import {AppRegistry,} from 'react-native';
//import Day0718 from './componets/Home'
let REQUEST_URL = 'https://api.douban.com/v2/movie/top250';
export default class Day0718 extends Component {
constructor(props) {
super(props);
this.state = {
dataSource:new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}),
loaded: false,
};
}
componentDidMount(){
this._fetchData();
}
_fetchData(){
fetch(REQUEST_URL)
.then(response => response.json())
.then(responseData =>{
this.setState({
movies:this.state.dataSource.cloneWithRows(responseData.subjects),
loaded: true,
});
})
.done();
}
render() {
if(!this.state.loaded){
return this._renderLoadingView();
}
return (
<View style={styles.Container}>
<ListView
dataSource={this.state.movies}
renderRow={this._renderMovieList}
style={styles.listView}
/>
</View>
);
}
_renderMovieList(movie){
return(
<View style = {styles.item}>
<View style = {styles.itemImage}>
<Image
style ={styles.image}
source ={{uri:movie.images.large}}/>
</View>
<View style = {styles.itemContent}>
<Text style ={styles.itemHeader}>{movie.title}</Text>
<Text style ={styles.itemMeta}>{movie.original_title}({movie.year})</Text>
<Text style ={styles.redText}>{movie.rating.average}</Text>
</View>
</View>
);
};
_renderLoadingView(){
return (
<View style ={styles.loading}>
<Text > loading movies.....</Text>
</View>
);
};
}
const styles = StyleSheet.create({
item:{
flexDirection:'row',
borderBottomWidth:1,
borderColor:'rgba(100,53,201,0.1)',
paddingBottom:6,
marginBottom:6,
flex:1,
},
itemContent:{
flex:1,
marginLeft:13,
marginTop:6,
},
itemHeader:{
fontSize:18,
fontFamily:'Helvetica Neue',
fontWeight:'300',
color:'#6435c9',
marginBottom:6,
},
itemMeta:{
fontSize:16,
color:'rgba(0,0,0,0.6)',
marginBottom:6,
},
redText:{
color:'#db2828',
},
listView:{
paddingTop: 20,
backgroundColor: '#F5FCFF',
},
loading:{
flex:1,
justifyContent:'center',
alignItems:'center',
},
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: 150,
width: 100,
justifyContent: 'center',
},
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);
请求豆瓣Top250数据,解析到ListView上展示
-----------------------------期待大神们的到来
------------------------一---起分享,一起进步!需要你们
React-Native基础_5.列表视图ListView 网络数据展示的更多相关文章
- React-Native基础_5.列表视图ListView
列表视图ListView 用来显示垂直滚动列表,需要指定两个东西,1 数据的来源 dataSource,2 渲染列表的条目布局 rendRow 'use strict' import React, { ...
- React Native基础&入门教程:初步使用Flexbox布局
在上篇中,笔者分享了部分安装并调试React Native应用过程里的一点经验,如果还没有看过的同学请点击<React Native基础&入门教程:调试React Native应用的一小 ...
- react native基础与入门
react native基础与入门 一.react native 的优点 1.跨平台(一才两用) 2.低投入高回报 (开发成本低.代码复用率高) 3.性能高:拥有独立的js渲染引擎,比传统的h5+ w ...
- 跨平台框架与React Native基础
跨平台框架 什么是跨平台框架? 这里的多个平台一般是指 iOS 和 Android . 为什么需要跨平台框架? 目前,移动开发技术主要分为原生开发和跨平台开发两种.其中,原生应用是指在某个特定的移动平 ...
- React Native填坑之旅--ListView篇
列表显示数据,基本什么应用都是必须.今天就来从浅到深的看看React Native的ListView怎么使用.笔者写作的时候RN版本是0.34. 最简单的 //@flow import React f ...
- Android 自学之列表视图ListView和ListActivity
ListView是手机系统中使用非常广泛的一种组件,它以垂直列表的形式显示所有列表项. 创建ListView有两种方式: 直接使用ListView创建. 让Activity继承ListActivity ...
- Android——列表视图(ListView)
列表视图是android中最常用的一种视图组件,它以垂直列表的形式列出需要显示的列表项.在android中有两种方法向屏幕中添加列表视图:一种是直接使用ListView组件创建:另外一种是让Activ ...
- 滚动视图、列表视图[ListView、SimpleAdapter类]
滚动视图 <ScrollView android: layout_width="fill_parent" android: layout_height="fill_ ...
- React Native基础&入门教程:调试React Native应用的一小步
React Native(以下简称RN)为传统前端开发者打开了一扇新的大门.其中,使用浏览器的调试工具去Debug移动端的代码,无疑是最吸引开发人员的特性之一. 试想一下,当你在手机屏幕按下一个按钮, ...
随机推荐
- Vue数据绑定失效
首先,我们得明白Vue数据响应的原理: 以对象为例:当把一个JavaScript对象传给Vue实例的data选项时,Vue将遍历此对象所有的属性,并使用Object.defineProperty把这些 ...
- Codeforces 235C. Cyclical Quest
传送门 写的时候挺蛋疼的. 刚开始的时候思路没跑偏,无非就是建个SAM然后把串开两倍然后在SAM上跑完后统计贡献.但是卡在第二个样例上就是没考虑相同的情况. 然后开始乱搞,发现会出现相同串的只有可能是 ...
- 20135302魏静静——linux课程第七周实验及总结
linux课程第七周实验及总结 实验及学习总结 1. 编译链接的过程和ELF可执行文件格式(以hello为例) GNU编译系统编译源码: 首先,运行C预处理器(cpp),将.c文件翻译成.i文件——g ...
- Xampp mysql启动
因为最近项目要用到php,需要集成Xampp环境,但是并没有接触过php,从官网下载了Xampp后,基本上就是傻瓜式安装了, 完成安装界面如下: 点击Apache的start可以正常启动,点击MYSQ ...
- [小问题笔记(八)] 常用SQL(读字段名,改字段名,打印影响行数,添加默认值,查找存储过程等)
读取所有字段,自然排序 declare @fields varchar(max) Select @fields=ISNULL(@fields,'')++name+',' from syscolumns ...
- 在lnmp下开启fileinfo扩展 Ubuntu系统
在lnmp下开启fileinfo扩展 Ubuntu系统 1.进入目录下 cd /usr/local/lnmp1.4-full/src/php-5.6.31/ext/fileinfo 2.phpize处 ...
- Ubuntu下搭建Spark运行环境
安装Spark的方式 现在有两种安装方式: 安裝spark notebook:已經把spark, scala, hadoop等等包起來了,裝好就能用GUI介面操作,適合測試用. 傳統方式安裝:慢慢裝s ...
- HTML子页面保存关闭并刷新父页面
1.思路是子页面保存后,后台传递成功的js到前台. 2.js的原理是——子页面调用父页面的刷新 子页面 function Refresh() { window.parent.Re ...
- CodeForces - 91B单调队列
有一个数列,对于每一个数,求比它小的在他右边距离他最远的那个数和他的距离 用单调队列做,维护单调队列时可采用如下方法,对于每一个数,如果队列中没有数,则加入队列,如果队列头的数比当前数大,则舍弃该数 ...
- 《深入理解mybatis原理1》 MyBatis的架构设计以及实例分析
<深入理解mybatis原理> MyBatis的架构设计以及实例分析 MyBatis是目前非常流行的ORM框架,它的功能很强大,然而其实现却比较简单.优雅.本文主要讲述MyBatis的架构 ...