無法正確對齊列表中的中間文本 (Can't get middle text in list aligned correctly)


問題描述

無法正確對齊列表中的中間文本 (Can't get middle text in list aligned correctly)

我正在嘗試製作付款摘要。左邊是日期,中間部分是發生,右邊是總和。從屏幕截圖中可以看出,左右對齊正確,但中間部分,在我的語言中稱為“hendelse”,沒有正確對齊:

在此處輸入圖片描述

代碼如下;

const Betalinger = [
{
    date:'16.04.2020',
    occurrence:'Utbetaling',
    sum: 11020,
},
{
    date:'15.03.2020',
    occurrence:'Utbetaling',
    sum: 8265,
},
{
    date:'14.02.2020',
    occurrence:'Utbetaling',
    sum: 8265,
},
{
    date:'14.01.2020',
    occurrence:'Utbetaling',
    sum: 8265,
},
{
    date:'14.12.2019',
    occurrence:'Utbetaling',
    sum: 8200,
},



];

導出默認函數Utbetaling() {

return(
    <SafeAreaView style={styles.container}>

        <View style = {styles.titleHeader}>
            <Text style={styles.titleText}>Dato</Text>
            <Text style={styles.titleText}>Hendelse</Text>
            <Text style={styles.titleText}>Beløp</Text>
        </View>

        <ScrollView>
            {Betalinger.map((item, index) => (
                <View  key = {index} style={styles.listItems}>
                    <Text style={styles.ItemText}>{item.date}</Text>
                    <Text style={styles.ItemText}>{item.occurrence + "     "}</Text>
                    <Text style={styles.ItemText}>{item.sum + " kr"}</Text>
                </View>

            ))}
        </ScrollView>

            <View>
            <TouchableOpacity style={styles.LinkContainer} onPress={() => Linking.openURL("https://lanekassen.no/nb‑NO/verktoy‑og‑frister/Frister‑i‑Lanekassen/utbetaling‑av‑utdanningsstotte/") }>
                <FontAwesome key ={0} name ={'arrow‑circle‑right'} size={30} color={'#4d264f'} />
            </TouchableOpacity>
            </View>


    </SafeAreaView>
);

和CCS:

const styles = StyleSheet.create({

container: {
    flex: 1,
    width: '100%',
    height: '100%',
},
titleHeader: {
    flexDirection: "row",
    justifyContent: "space‑around",
    alignItems: "center",
    backgroundColor: '#4d264f',
    height: "15%",
    width: "100%",
    bottom: 10,
},
titleText: {
    color: "white",
    fontSize: 16,
},
listItems: {
    flexDirection: "row",
    borderBottomWidth: 1,
    justifyContent: "space‑around",
    marginBottom: 10,
},
ItemText: {
    fontSize: 15,
    marginBottom: 10,
},
LinkContainer: {
    right: 0,
    bottom: 0
},

非常歡迎任何提示:))


參考解法

方法 1:

This might be because the dates are wider than the other two texts. Can you try giving every ItemText the same fixed width, so that justifyContent: "space‑around" can position them equal?

方法 2:

You can try following styles :

listItems: {
    flexDirection: "row",
    borderBottomWidth: 1,
    justifyContent: "space‑around",
    marginBottom: 10,
    flex: 1,
},
ItemText: {
    fontSize: 15,
    marginBottom: 10,
    flex: 1/3,
    textAlign: 'center'
},

and result will be like this : enter image description here

(by Ingvild HagenphilmanManju JK)

參考文件

  1. Can't get middle text in list aligned correctly (CC BY‑SA 2.5/3.0/4.0)

#css #react-native #list #alignment






相關問題

在圖像上淡入文本 (Fade in text over an image)

可以使用 css3 轉換輪廓顏色 (possible to transition outline color with css3)

以背景色為條件的 if 語句 (If statement with background color as condition)

Nội dung từ <p> biến mất khi tôi quay lại trang (Content from <p> disappears when I return to the page)

當按鈕向右浮動時,ng-click 不起作用 (ng-click doesn't work when the button is floated to the right)

帶有偽 css 的背景顏色層 (Background color layer with pseudo css)

是否可以製作離線工作的網絡應用程序? (Is it possible to make a web-app which works offline?)

chrome中帶有省略號的多行文本問題 (issue with multiline text with ellipsis in chrome)

將字符串轉換為類的安全名稱 (Convert string to safe name for class)

絕對定位跨度收縮 (Absolute Positioned Span Shrinks)

如何設置單選按鈕的樣式,使其看起來像普通的可點擊按鈕? (How do I style a radio button to look like a normal clickable button?)

無法獲得白色和灰色的 CSS 進度條 (Not able to get the CSS progress bar with white and grey)







留言討論