我用簡單的Text項創建一個簡單的ListView組件。React Native:ListView項不能縮放全寬
import React from "react";
import { StyleSheet, Text, View, ListView } from "react-native";
export default class NoteList extends React.Component {
constructor(props) {
super(props);
this.ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => {
r1 !== r2;
}
});
}
render() {
return (
<ListView
dataSource={this.ds.cloneWithRows([
{ title: "Note 1", body: "Body 1", id: 1 },
{ title: "Note 2", body: "Body 2", id: 2 }
])}
renderRow={rowData => {
return (
<View style={styles.itemContainer}>
<Text style={styles.itemText}>
{rowData.title}
</Text>
</View>
);
}}
/>
);
}
}
const styles = StyleSheet.create({
itemContainer: {
flex: 1,
flexDirection: "row",
justifyContent: "flex-start",
borderColor: "red",
borderWidth: 1
},
itemText: {
padding: 16,
borderColor: "blue",
borderWidth: 1
}
});
我使用包裝視圖的文本。然後使用FlexBox將文本縮放爲全寬並將其內容與左側對齊。但結果並不像預期的那樣,當文本對齊中心和包裝內容(包裝視圖也包裝內容)。如何解決這個問題?
你是什麼意思創建組件'文本'全寬? – muhammadaa