我不知道你在哪里应用了这些样式 width: "25%" 或 flex: 1,因为你不能根据 react-native 文档直接为 Button 组件提供样式。因此,您需要将 Button 组件包装在 View 中并将样式应用于该 View。
顺便说一句,在您的情况下 width: '25%' 和 flex: 1 都有效,下面是代码。
import React, { Component } from 'react';
import { View, StyleSheet,FlatList,Button } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<FlatList
data={['1', '2', '3', '4', '5', '6', '7', '8']}
numColumns={4}
renderItem={({ item }) => (
<View style={{flex:1,height:100}} >
<Button title={item} />
</View>
)}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ecf0f1',
},
});
小吃演示 - https://snack.expo.io/SkidXdPDZ