ListView实现中的TextView重叠,android有2个TextView

ListView实现中的TextView重叠,android有2个TextView,android,listview,Android,Listview,我用2个文本视图实现listview,仅供参考 我使用的不是短的股票名称,而是长文本,因此当我使用长文本时,它与第二个重叠 因此,如何正确处理,使两个文本视图不会相互重叠 为了避免重叠,您可以将第二个文本视图设置为向右对齐(android:layout\u toRightOf) 例如: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation=

我用2个文本视图实现listview,仅供参考

我使用的不是短的股票名称,而是长文本,因此当我使用长文本时,它与第二个重叠


因此,如何正确处理,使两个文本视图不会相互重叠

为了避免重叠,您可以将第二个文本视图设置为向右对齐(android:layout\u toRightOf)

例如:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_symbol"
        android:layout_alignParentLeft="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_price"
        android:layout_toRightOf="@id/ticker_symbol"
        android:layout_alignParentRight="true"  />
</RelativeLayout>

您可以使用以下代码来解决问题:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="1">
    <TextView
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_symbol"

         android:text="sdasd sadas"
         android:layout_weight=".5"/>
    <TextView
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_price"
         android:text="dfsd"
         android:layout_weight=".5"
         android:gravity="right" />
</LinearLayout>

输出:


我猜您的意思是,由于文本长度较长,它会转到下一行或下一个文本视图

因此,我建议您使用textView属性android:ellipsized=“end”,也可以使用android:single\u line=“true”,这样您就可以直接指定maxline=1 我不确定姓名拼写是否正确,所以键入时请检查

<TextView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_symbol"
        android:ellipsezed="end"
        android:singe_line="true"  
        android:layout_alignParentLeft="true" />


希望这个解释对您有用,让我知道。

是的,在示例中是这样的,但它仍然与一个文本视图重叠,我的第二个文本视图根本没有移动,第一个文本视图与之重叠。行
android:layout\u toRightOf=“@id/ticker\u symbol”
是我添加的。它不在最初的例子中。您可以添加您正在使用的XML代码以便我们讨论它吗?您还可以使用
android:weight
属性将每个文本视图的宽度设置为50%,而不是
wrap\u content
。检查一下这个xml文件和你在上面发布的是一样的,和上面一样,在相对布局中我不能使用android:Weight我使用相对布局而不是线性布局,所以它不起作用。使用线性布局有什么具体的原因吗?我还有一个问题。如果第一个文本视图的内容会增加,那么文本视图的内容会转到下一行还是没有显示?