【问题标题】:How to position two TextViews in a ListView next to each other, but having at least a certain gap如何将两个 TextViews 定位在 ListView 中彼此相邻,但至少有一定的差距
【发布时间】:2014-12-21 05:27:51
【问题描述】:

我想让我的两个 TextView 彼此相邻放置,但它们之间至少有一定的空间。因为 TextView 是 ListView 的一部分,所以接收数据有时会有所不同。所以我想要实现的是第一个 TextView,即使它包含比前一个更短的文本,也可以为下一个 TextView 获得相同的填充。

这是 ma 布局文件:

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>   

这里我给你看一个例子like

您看到的是,编号为 140 的条目与右侧的 TextView 有更大的差距。我能做些什么来让所有其他条目保持相同的差距吗?

感谢您的帮助!

【问题讨论】:

    标签: android listview layout android-listview textview


    【解决方案1】:

    最好给你的 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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      • 2014-07-15
      • 2016-05-24
      • 2015-07-27
      • 2018-03-31
      • 2021-06-04
      相关资源
      最近更新 更多