簡體   English   中英

如何將兩個TextView彼此相鄰放置在ListView中,但至少有一定的間隔

[英]How to position two TextViews in a ListView next to each other, but having at least a certain gap

我想讓我的兩個TextView彼此相鄰放置,但它們之間至少要有一定的間隔。 由於TextView是ListView的一部分,因此接收數據有時會有所不同。 因此,我想實現的是,即使第一個TextView包含的文本比上一個短,但它對下一個TextView的填充還是相同的。

這是一個布局文件:

LayoutFile.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/balken_clear" >

    <TextView
        android:id="@+id/line_color"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:paddingTop="12dp"
        android:background="#15aba4"
        android:paddingRight="10dp" />

    <TextView
        android:id="@+id/realtime_line"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/line_color"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:textColor="#00003d"
        android:textSize="22sp" />

    <TextView
        android:id="@+id/realtime_direction"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/realtime_line"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:textColor="#00003d"
        android:textSize="22sp" />

    <TextView
        android:id="@+id/realtime_arrivaltime"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:paddingLeft="10dp"
        android:paddingRight="16dp"
        android:textColor="#00003d"
        android:textSize="22sp" />

</RelativeLayout>   

在這里,我向您展示一個示例,它看起來什么

您將看到,編號為140的條目與右側的TextView的差距更大。 我有什么辦法可以使所有其他條目具有相同的差距?

感謝您的幫助!

最好給您的realtime_line一個固定的寬度...以便每次它占用相同的空間而不是它所占的空間.....為可以插入的最大值提供空間

例:

140是3位數,因此如果最多3位數,則可以將其固定為60 dp寬度...

<TextView
    android:id="@+id/realtime_line"
    android:layout_width="60dp"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/line_color"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:textColor="#00003d"
    android:textSize="22sp" />

<TextView
    android:id="@+id/realtime_direction"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/realtime_line"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:textColor="#00003d"
    android:textSize="22sp" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM