• ReactNative


    在expo的项目下:

    import {useState} from “react”


    //引进需要用的组件:

    import {

      StatusBar,

      StyleSheet,

      Text,

      View,

      Image,

      ImageBackground,

      TextInput,

      ScrollView,

      Button,

      TouchableOpacity,

    } from "react-native";



    //native中的布局元素默认就是弹性盒
    //不需要再去设置display:flex
    //弹性盒的主轴方向和web端是相反的,是纵向的
    //view不能加onPress事件的

     

    第一次课
     

    1. export default function App() {
    2. return (
    3. <View style={styles.container}>
    4. {/* 方法一 */}
    5. {/* <View style={styles.container}> */}
    6. {/* 点击事件,输出在终端 */}
    7. <Text onPress={() => {console.log('123')}} style={styles.textColor}>康康同学,你好啊!Text>
    8. <Text onPress={() => {console.log('点击了')}} >今天 天气好晴朗Text>
    9. {/* Text不能继承外层View字体样式的,能够继承父级Text组件样式 */}
    10. {/* Text可以加事件 */}
    11. <Text onPress={() => {console.log('点击了')}} >普通文本<Text>节点Text>Text>
    12. <StatusBar backgroundColor="purple"/>
    13. View>
    14. );
    15. }
    对应的样式代码:
    1. container: {
    2. // 第一次课
    3. // 方法二:可以注释掉样式
    4. // flex: 1,
    5. backgroundColor: 'pink',
    6. height: 200,
    7. // 注意大写问题
    8. alignItems: 'center',
    9. justifyContent: 'center',
    10. },
    11. textColor: {
    12. color: 'yellow',
    13. fontSize: 40,
    14. },

    第二次课:

    1. // import { StatusBar } from 'expo-status-bar';
    2. import { useState } from "react";
    3. // 在这里引进需要用的组件
    4. import {
    5. StatusBar,
    6. StyleSheet,
    7. Text,
    8. View,
    9. Image,
    10. ImageBackground,
    11. TextInput,
    12. ScrollView,
    13. Button,
    14. TouchableOpacity,
    15. } from "react-native";
    16. // native中的布局元素默认就是弹性盒
    17. // 不需要再去设置display:flex
    18. // 弹性盒的主轴方向和web端是相反的,纵向
    19. // View不能加onPress事件的
    20. export default function App() {
    21. const [value, setValue] = useState("");
    22. return (
    23. //
    24. <ScrollView>
    25. <TouchableOpacity
    26. style={{
    27. backgroundColor: "red",
    28. height: 100,
    29. width: 200,
    30. justifyContent: "center",
    31. alignItems: "center",
    32. borderRadius: 50,
    33. }}
    34. onPress={() => {
    35. }}
    36. >TouchableOpacity>
    37. {/* <Button style={{ width: 100, height: 100, backgroundColor: "red" }}>Button> */}
    38. {/* <Text>{value}Text>
    39. <TextInput
    40. value={value}
    41. onChangeText={(text) => setValue(text)}
    42. style={{
    43. width: 300,
    44. height: 30,
    45. borderColor: "red",
    46. borderWidth: 1,
    47. borderRadius: 10,
    48. }}
    49. >TextInput> */}
    50. {/* <Image
    51. // resizeModecover覆盖center:居中repeat平铺很多个
    52. style={{ width: 100, height: 100, resizeMode:"center",borderColor: "blue", borderWidth: 1 }}
    53. source={require("./assets/favicon.png")}
    54. // 引入网络图片之前需要先设置大小
    55. />
    56. <Image
    57. style={{ width: 100, height: 100, resizeMode:"contain",borderColor: "blue", borderWidth: 1 }}
    58. source={require("./assets/icon.png")}
    59. // 引入网络图片之前需要先设置大小
    60. />
    61. <Image
    62. // 左右上下有空白
    63. resizeMode="contain"
    64. style={{ width: 200, height: 100, borderColor: "red", borderWidth: 1, position:"absolute" }}
    65. // 后缀为svg的可能出不来效果
    66. source={{uri: "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png"}}
    67. /> */}
    68. {/* 布局元素设置了display:flex,position:relative */}
    69. {/* <Image
    70. style={{ width: 100, height: 100, position:"absolute" }}
    71. source={require("./assets/icon.png")}
    72. // 引入网络图片之前需要先设置大小
    73. />
    74. <Text>hello worldText>
    75. */}
    76. {/* 文本是以背景图左上角为起始点开始的 */}
    77. {/* <ImageBackground
    78. source={require("./assets/icon.png")}
    79. style={{ width: 200, height: 100 }}
    80. >
    81. <Text>hello worldText>
    82. ImageBackground> */}
    83. {/*
    84. <TextInput
    85. style={{
    86. borderWidth: 1,
    87. borderColor: "red",
    88. width: 300,
    89. height: 100,
    90. borderRadius: 10,
    91. alignSelf: "center",
    92. margin: 20,
    93. paddingHorizontal: 20,
    94. }}
    95. >TextInput> */}
    96. {/* View> */}
    97. ScrollView>
    98. );
    99. }
    100. // 第一次课
    101. // export default function App() {
    102. // return (
    103. //
    104. // {/* 方法一 */}
    105. // {/* */}
    106. // {/* 点击事件,输出在终端 */}
    107. // {console.log('123')}} style={styles.textColor}>康康同学,你好啊!
    108. // {console.log('点击了')}} >今天 天气好晴朗
    109. // {/* Text不能继承外层View字体样式的,能够继承父级Text组件样式 */}
    110. // {/* Text可以加事件 */}
    111. // {console.log('点击了')}} >普通文本节点
    112. //
    113. //
    114. // );
    115. // }
    116. const styles = StyleSheet.create({
    117. // container: {
    118. // // 第一次课
    119. // // 方法二:可以注释掉样式
    120. // // flex: 1,
    121. // backgroundColor: 'pink',
    122. // height: 200,
    123. // // 注意大写问题
    124. // alignItems: 'center',
    125. // justifyContent: 'center',
    126. // },
    127. // textColor: {
    128. // color: 'yellow',
    129. // fontSize: 40,
    130. // },
    131. container: {
    132. flex: 1,
    133. backgroundColor: "#fff",
    134. alignItems: "center",
    135. justifyContent: "center",
    136. height: 200,
    137. },
    138. });

  • 相关阅读:
    Spring Data JPA @Entity之间的关联关系注解如何正确使用?
    AndroidT(13) -- logger_write 库实现解析(四)
    朔雪流量复制器的前端
    MTD之 UBOOT向内核传参
    Redisson分布式锁详解
    【java刷算法】牛客—剑指offer4DFS与BFS两种思路的碰撞,一起来练习吧
    【JVM笔记】异常处理字节码指令
    国际版腾讯云/阿里云:云解析DNS是什么
    DDD领域驱动设计-上下文映射
    智安网络|揭开云服务的神秘面纱:其含义和功能的综合指南
  • 原文地址:https://blog.csdn.net/qq_64662981/article/details/136749225