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移动端的代码,无疑是最吸引开发人员的特性之一. 试想一下,当你在手机屏幕按下一个按钮, ...
随机推荐
- uboot下如何查看内存里的数据
答:使用md工具 md.b $address $count (从地址$address处显示$count个字节的数据,b=byte,8位) md.w $address $count (从地址$addre ...
- mybatis的一对多
1.配置文件 db.properties db.driver=com.mysql.jdbc.Driver db.url=jdbc:mysql://localhost:3306/demo?useUnic ...
- org.springframework.dao.DuplicateKeyException: a different object with the same identifier value was
在使用hibernate框架里面的:saveOrUpdate报错: 意思就是另一个对象的id(id同值)已经被session关联了. 原因分析: 在第1步中中通过titleList.get(0)获取一 ...
- Linux 实用操作命令
1. ssh远程连接服务器命令 ssh [username@]hostname 2. 查看远程服务器近期登陆记录 last 3. 用户及其主目录的创建 1. useradd –d /home/lb ...
- LA 7272 Promotions(dfs)
https://vjudge.net/problem/UVALive-7272 题意: 公司要提拔人,现在有n个人,现在有m条有向边,A->B表示A的表现比B好,也就是如果B晋升了,那么A肯定会 ...
- 关于Eclipse SVN 分支 与主干 小结
SVN建立分支和合并代码 https://blog.csdn.net/luofeixiongsix/article/details/52052631 SVN创建指定版本号的分支 https://blo ...
- IE与DOM的事件监听
IE 事件监听 标准DOM不支持 注意几点: window.onload attachEvent detachEvent 标准DOM监听,ie不支持
- Google Java编程风格指南中文版(转)
作者:Hawstein出处:http://hawstein.com/posts/google-java-style.html声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Cre ...
- JavaScript权威指南--词法结构
使用广泛,所有的浏览器(桌面.手机.屏蔽等等)都配有相应的JavaScript解析器. JavaScript解析器如何工作? 浏览器在读取HTML文件的时候,只有当遇到<script>标签 ...
- 英语每日写作---4、VOA慢速英语(翻译+字幕+讲解):专家:城市发展将加剧住房危机
英语每日写作---4.VOA慢速英语(翻译+字幕+讲解):专家:城市发展将加剧住房危机 一.总结 一句话总结: takes place 发生deal with 处理:应付population grow ...