ReactNative学习十五-横竖布局及右上角圆点

前端之家收集整理的这篇文章主要介绍了ReactNative学习十五-横竖布局及右上角圆点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.效果


2.源代码

  1. 'use strict';
  2.  
  3. import React,{
  4. Component,View,Image,Text,Dimensions,StyleSheet
  5. } from 'react-native';
  6.  
  7. var deviceWidth = Dimensions.get('window').width;
  8.  
  9. export default class MyView extends React.Component {
  10. render()
  11. {
  12. return (
  13. <View style={styles.container}>
  14. <View style={ styles.person }>
  15. <Image source={require('./images/banner/2.jpg')} style={styles.imageOutside}>
  16. <Image source={require('./point.png')} style={styles.imageInside}/>
  17. </Image>
  18. </View>
  19.  
  20. <View style={ styles.person }>
  21.  
  22. <Image style={ styles.personImage } source={require('./images/banner/2.jpg') } />
  23. <View style={ styles.personInfo }>
  24.  
  25. <Text style={ styles.personName }>
  26. firstName
  27. </Text>
  28.  
  29. <View style={ styles.personscore }>
  30. <Text style={ styles.personscoreHeader }>
  31. WON
  32. </Text>
  33. <Text style={ [styles.personscoreValue,styles.won] }>
  34. won
  35. </Text>
  36. </View>
  37.  
  38. <View style={ styles.personscore }>
  39. <Text style={ styles.personscoreHeader }>
  40. LOST
  41. </Text>
  42. <Text style={ [styles.personscoreValue,styles.lost] }>
  43. lost
  44. </Text>
  45. </View>
  46.  
  47. <View style={ styles.personscore }>
  48. <Text style={ styles.personscoreHeader }>
  49. score
  50. </Text>
  51. <Text style={ styles.personscoreValue }>
  52. score
  53. </Text>
  54. </View>
  55.  
  56. </View>
  57. </View>
  58. </View>
  59. );
  60. }
  61. }
  62.  
  63. const styles = StyleSheet.create({
  64. container: {
  65. flex: 1,paddingTop:5,paddingLeft:5,paddingRight:5,paddingBottom:5,},imageOutside:{//类似android相对布局外图
  66. alignSelf:'center',//自身中间对齐
  67. justifyContent:'flex-start',//主轴左对齐
  68. resizeMode: 'stretch',height:150,width:330
  69. },imageInside:{//类似android相对布局右上角小圆点
  70. alignSelf:'flex-end',//自身右对齐
  71. },person: {
  72. margin: 10,borderRadius: 3,overflow: 'hidden'
  73. },personInfo: {
  74. borderLeftColor: 'rgba( 0,0.1 )',borderLeftWidth: 1,borderRightColor: 'rgba( 0,borderRightWidth: 1,borderBottomColor: 'rgba( 0,borderBottomWidth: 1,padding: 10,alignItems: 'center',flexDirection: 'row'
  75. },personImage: {
  76. width: deviceWidth,//设备宽(只是一种实现,此处多余)
  77. height: 150,resizeMode: 'stretch'
  78. },personName: {
  79. fontSize: 18,flex: 1,fontWeight :'bold',paddingLeft: 5
  80. },personscore: {
  81. flex: 0.25,alignItems: 'center'
  82. },personscoreHeader: {
  83. color: 'rgba( 0,0.3 )',fontSize: 10,fontWeight: 'bold'
  84. },personscoreValue: {
  85. color: 'rgba( 0,0.6 )',fontSize: 16
  86. },won: {
  87. color: '#93C26D'
  88. },lost: {
  89. color: '#DD4B39'
  90. }
  91. });

猜你在找的React相关文章