我的react-native元素有問題。我有一個<Parent>組件是 aView并且我有一個<Child>組件作為子組件也是View. 我想這<Child>將永遠是100%的寬度和高度<Parent>。我知道我可以通過width: '100%',height: '100%'但這是一種設計風格的好方法嗎?設定父組件和子組件的最佳實踐是什么,父組件將定義寬度和高度,而子組件將始終取決于父組件?
uj5u.com熱心網友回復:
為此,您可以使用這樣flex的樣式:
import React from "react";
import { StyleSheet, Text, View } from "react-native";
const Flex = () => {
return (
<View style={[styles.container, {
// Try setting `flexDirection` to `"row"`.
flexDirection: "column"
}]}>
<View style={{ flex: 1, backgroundColor: "red" }} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default Flex;
有關更多資訊,請參閱此
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/376803.html
上一篇:如何正確取消訂閱Firebase實時資料庫的onValue偵聽器
下一篇:如何使用變數查找物件鍵?
