react-native - 如果高度为百分比,如何根据父组件的高度设置文本的字体大小?
问题描述
import React from "react";
import { Image, StyleSheet, Text, View } from "react-native";
function ProductCard2({ style }) {
return (
<View style={style}>
<Image
style={styles.image}
source={{ uri: "https://picsum.photos/1440/2842?random=${1}" }}
/>
<Text style={styles.title}>
Momo
</Text>
<Text style={styles.price}>Rs 100</Text>
</View>
);
}
const styles = StyleSheet.create({
image: {
flex: 7,
},
title: { flex: 1, textAlignVertical: "center", fontSize: 24 },
price: { flex: 1, textAlignVertical: "center", fontSize: 21 },
});
export default ProductCard2;
这里的 style 属性包含高度的百分比。如何使我的 fontSize 取决于 View 组件的高度?我不能在样式道具中使用高度值,因为它是百分比。
解决方案
推荐阅读
- google-cloud-platform - 将文件从 VM 复制到 GCP 上的云存储桶
- python - ffmpeg 通过管道传输到 python 并显示 cv2.imshow 向右滑动并更改颜色
- ios - Firebase 云消息未发送到 iOS(停留在“预定”状态)
- git - 如何更改 HEAD 指向的远程分支?
- php - 在 Laravel 中使用不同的 redis 连接来处理作业
- upload - Jersey File Upload中FormDataContentDisposition的问题
- html - 如何创建轮播滑块推荐
- c# - 保护用 .Net 4.7 编写的 WPF 应用程序的代码
- c++ - 包含指向指针的对象的深层副本
- r - 为什么 R 不能通过词法作用域找到参数的值?