问题描述
我想将文本与视图的右下角对齐。我已使用
将文本向右对齐textAlign:'center'
谢谢
解决方法
工作示例:Expo Snack
您可以通过以下方式轻松地将 Text
对齐到任何位置:
import * as React from 'react';
import { Text,View,StyleSheet } from 'react-native';
import Constants from 'expo-constants';
export default function App() {
return (
<View style={styles.container}>
<View style={styles.card}>
<View style={{ position: 'absolute',bottom: 10,right: 10 }}>
<Text>Bottom Right</Text>
</View>
<View style={{ position: 'absolute',left: 10 }}>
<Text>Bottom Left</Text>
</View>
<View style={{ position: 'absolute',top: 10,right: 10 }}>
<Text>Top Right</Text>
</View>
<View style={{ position: 'absolute',left: 10 }}>
<Text>Top Left</Text>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,justifyContent: 'center',alignItems: 'center',paddingTop: Constants.statusBarHeight,backgroundColor: '#ecf0f1',padding: 8,},card: {
width: 200,height: 200,borderRadius: 10,borderWidth: 5,});