React-Native入门指南

    一、实现第一部分

    1. 4、完成初步布局
    2. 看如下代码,应该很清楚了,View里面嵌入并列的两栏。

    美团

    1. 5、添加内部图片和文字
    2. 其实做这种布局,还是有很多的细节,粗糙的效果如下,这块代码暂时不贴了,最后一并贴出来:

    二、按照第一部分原理,完成整个页面

    1. 整个代码如下:
    2. /**
    3. * Sample React Native App
    4. * https://github.com/facebook/react-native
    5. */
    6. 'use strict';
    7. var React = require('react-native');
    8. var {
    9. AppRegistry,
    10. StyleSheet,
    11. Text,
    12. View,
    13. Image,
    14. } = React;
    15. var HelloWorld = React.createClass({
    16. render: function() {
    17. return (
    18. <View style={{}}>
    19. <View style={[styles.height160, styles.row,]}>
    20. <View style={[styles.height160, styles.part_1_left,]}>
    21. <Text style={[styles.font14, styles.marTop18, styles.marLeft10, styles.green]}>我们约吧</Text>
    22. <Text style={[styles.font10, styles.marTop14, styles.marLeft10]}>恋爱家人好朋友</Text>
    23. <Image style={[styles.yue]} source={{uri: 'http://p0.meituan.net/mmc/fe4d2e89827aa829e12e2557ded363a112289.png'}}></Image>
    24. </View>
    25. <View style={[styles.height160, styles.part_1_right,]}>
    26. <View style={[styles.row, {flex:1}]}>
    27. <View style={{flex:1}}>
    28. <Text style={[styles.font14, {marginLeft:30}, styles.red]}>超低价值</Text>
    29. <Text style={[styles.font14, {fontSize:12, marginTop:14, marginLeft:30,color: 'black'}]}>十元惠生活</Text>
    30. </View>
    31. <View style={[{flex:1}, {marginTop:-13}]}>
    32. <Image style={[styles.hanbao]} source={{uri: 'http://p0.meituan.net/mmc/a06d0c5c0a972e784345b2d648b034ec9710.jpg'}}></Image>
    33. </View>
    34. </View>
    35. <View style={[{flex:1, flexDirection: 'row',borderTopWidth:0.5, borderColor:'#DDD8CE'}]}>
    36. <View style={{flex:1, borderRightWidth:1, borderColor:'#DDD8CE',}}>
    37. <Text style={{color:'#F742AB', marginLeft:5,fontWeight:'bold', fontSize:15, marginTop:8}}>聚餐宴请</Text>
    38. <Text style={{fontSize:12,marginTop:4, marginLeft:5}}>朋友家人常聚聚</Text>
    39. <Image style={{height:25,width:25, alignSelf: 'center'}} source={{uri: 'http://p1.meituan.net/mmc/08615b8ae15d03c44cc5eb9bda381cb212714.png'}}></Image>
    40. </View>
    41. <View style={{flex:1,}}>
    42. <Text style={[styles.font14,{color:'#FF8601', marginTop:8, marginLeft:5}]}>名店抢购</Text>
    43. <Text style={[{marginLeft:5, fontSize:12,marginTop:4,}]}>还有</Text>
    44. <Text style={[{marginLeft:5, fontSize:12,marginTop:4,}]}>12:06:12分</Text>
    45. </View>
    46. </View>
    47. </View>
    48. <View style={{borderBottomWidth:1,borderTopWidth:1, borderColor:'#DDD8CE', marginTop:40,height:65, flexDirection: 'row',paddingTop:10}}>
    49. <View style={[{flex:1}]}>
    50. <Text style={{fontSize:17, color:'#FF7F60', fontWeight:'900', marginLeft:7}}>一元吃大餐</Text>
    51. <Text style={{marginLeft:7, fontSize:12, marginTop:3}}>新用户专享</Text>
    52. </View>
    53. <View style={{flex:1}}>
    54. <Image style={{height:50, width:120}} source={{uri:'http://p1.meituan.net/280.0/groupop/7f8208b653aa51d2175848168c28aa0b23269.jpg'}}></Image>
    55. </View>
    56. </View>
    57. </View>
    58. <View>
    59. <View style={{flexDirection: 'row',}}>
    60. <View style={[styles.row, {borderColor:'#DDD8CE', borderRightWidth:1}]}>
    61. <View style={{flex:1,}}>
    62. <Text style={{fontSize:17, color:'#EA6644', fontWeight:'bold', marginLeft:7}}>撸串节狂欢</Text>
    63. <Text style={{fontSize:12, color:'#97979A', marginTop:3, marginLeft:7}}>烧烤6.6元起</Text>
    64. </View>
    65. <View style={{flex:1}}>
    66. <Image style={{width:60,height:55}} source={{uri: 'http://p1.meituan.net/280.0/groupop/fd8484743cbeb9c751a00e07573c3df319183.png'}}></Image>
    67. </View>
    68. </View>
    69. <View style={styles.row}>
    70. <View style={{flex:1}}>
    71. <Text style={{fontSize:17, color:'#EA6644', fontWeight:'bold', marginLeft:7}}>毕业旅行</Text>
    72. <Text style={{fontSize:12, color:'#97979A', marginTop:3, marginLeft:7}}>选好酒店才安心</Text>
    73. </View>
    74. <View style={{flex:1}}>
    75. <Image style={{width:60,height:55}} source={{uri: 'http://p0.meituan.net/280.0/groupop/ba4422451254f23e117dedb4c6c865fc10596.jpg'}}></Image>
    76. </View>
    77. </View>
    78. </View>
    79. <View style={{flexDirection: 'row',}}>
    80. <View style={[styles.row, {borderColor:'#DDD8CE', borderRightWidth:1, marginLeft:1},]}>
    81. <View style={{flex:1}}>
    82. <Text style={{fontSize:17, color:'#EA6644', fontWeight:'bold', marginLeft:7}}>0元餐来袭</Text>
    83. <Text style={{fontSize:12, color:'#97979A', marginTop:3, marginLeft:7}}>免费吃喝玩乐购</Text>
    84. </View>
    85. <View style={{flex:1}}>
    86. <Image style={{width:60,height:55}} source={{uri: 'http://p0.meituan.net/280.0/groupop/6bf3e31d75559df76d50b2d18630a7c726908.png'}}></Image>
    87. </View>
    88. </View>
    89. <View style={styles.row}>
    90. <View style={{flex:1}}>
    91. <Text style={{fontSize:17, color:'#EA6644', fontWeight:'bold', marginLeft:7}}>热门团购</Text>
    92. <Text style={{fontSize:12, color:'#97979A', marginTop:3, marginLeft:7}}>大家都在买什么</Text>
    93. </View>
    94. <View style={{flex:1}}>
    95. <Image style={{width:60,height:55}} source={{uri: 'http://p1.meituan.net/mmc/a616a48152a895ddb34ca45bd97bbc9d13050.png'}}></Image>
    96. </View>
    97. </View>
    98. </View>
    99. </View>
    100. </View>
    101. }
    102. var styles = StyleSheet.create({
    103. row:{
    104. flexDirection: 'row',
    105. paddingTop:20
    106. },
    107. marTop18:{
    108. marginTop:18,
    109. },
    110. marTop14:{
    111. marginTop:14,
    112. },
    113. font14:{
    114. fontSize:14,
    115. },
    116. font10:{
    117. fontSize:12,
    118. },
    119. height160:{
    120. height: 160
    121. },
    122. yue:{
    123. height:80,
    124. },
    125. green:{
    126. color:'#55A44B',
    127. fontWeight: '900'
    128. },
    129. red:{
    130. color: '#FF3F0D',
    131. fontWeight: '900'
    132. },
    133. marLeft10:{
    134. marginLeft:10,
    135. },
    136. part_1_left:{
    137. flex: 1,
    138. borderColor: '#DCD7CD',
    139. borderRightWidth: 0.5,
    140. borderBottomWidth: 1,
    141. },
    142. part_1_right:{
    143. flex:2,
    144. borderColor: '#DCD7CD',
    145. borderBottomWidth: 1,
    146. },
    147. hanbao:{
    148. height:55,
    149. width:55
    150. }
    151. });