【发布时间】:2019-12-24 13:11:45
【问题描述】:
新的反应原生并尝试设置我已添加表格的页面的样式。我想更改页面的背景颜色,但似乎无法弄清楚是否有人可以帮我一把,而且在桌子上我有一个按钮,但它稍微向左(见截图)我尝试过使用不同的位置选项,但没有任何变化,如何在单元格内居中按钮?
谢谢
import { StyleSheet, View, Text, TouchableOpacity, Alert } from "react-native";
import { Table, TableWrapper, Row, Cell } from "react-native-table-component";
export default class ExampleFour extends Component {
constructor(props) {
super(props);
this.state = {
tableHead: ["Head", "Head2", "Head3", "Head4"],
tableData: [
["1", "2", "3", "4"],
["a", "b", "c", "d"],
["1", "2", "3", "4"],
["a", "b", "c", "d"]
]
};
}
_alertIndex(index) {
Alert.alert(`This is row ${index + 1}`);
}
render() {
const state = this.state;
const element = (data, index) => (
<TouchableOpacity onPress={() => this._alertIndex(index)}>
<View style={styles.btn}>
<Text style={styles.btnText}>button</Text>
</View>
</TouchableOpacity>
);
return (
<View style={styles.container}>
<Table borderStyle={{ borderWidth: 1 }}>
<Row
data={state.tableHead}
style={styles.head}
textStyle={styles.text}
/>
{state.tableData.map((rowData, index) => (
<TableWrapper key={index} style={styles.row}>
{rowData.map((cellData, cellIndex) => (
<Cell
key={cellIndex}
data={cellIndex === 3 ? element(cellData, index) : cellData}
textStyle={styles.text}
/>
))}
</TableWrapper>
))}
</Table>
</View>
);
}
}
const styles = StyleSheet.create({
container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: "#fff" },
head: { height: 40, backgroundColor: "#808B97" },
text: { margin: 6 },
row: { flexDirection: "row", backgroundColor: "white" },
btn: {
width: 58,
height: 18,
backgroundColor: "black",
borderRadius: 2
},
btnText: { textAlign: "center", color: "#fff" }
});
【问题讨论】:
-
朋友我来帮你看看这个博览会snack.expo.io/@yoel301/stackover
标签: reactjs react-native react-native-android