如何获得并排文本视图与换行文本视图

发布于 2024-10-09 04:21:01 字数 1543 浏览 0 评论 0原文

我有一个带有自定义适配器的 listview ,其中有 3 个 textview ,其中两个彼此相邻,一个位于其他视图下方。我遇到的问题是,当第一个 textview 扩展时,它将另一个 textview 推离屏幕。

我无法成功地使其工作,这是发生的情况的示例:

alt text

正如您所看到的,当第一个 textview 变得太长时,它就会推送另一个文字离开屏幕。我希望它能换行,但日期 textview 也显示出来。它也应该在水平视图中发挥作用。

这是 listview 适配器代码:

<RelativeLayout android:id="@+id/vw1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:descendantFocusability="blocksDescendants" xmlns:android="http://schemas.android.com/apk/res/android">


<TextView android:id="@+id/liName" android:textSize="17sp"
    android:textColor="#333" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:gravity="left"
    android:layout_gravity="left" />
<TextView android:id="@+id/liDate" android:textSize="12sp"
    android:textColor="#666" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:gravity="right"
    android:layout_gravity="right" android:width="60sp" android:layout_toRightOf="@+id/liName" />

<TextView android:id="@+id/liNum" android:textSize="12sp"
    android:textColor="#666" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_below="@+id/liName" />


</RelativeLayout>

I have a listview with a custom adapter in which I have 3 textviews, two are next to each other and one is below the others. The problem I am running into though, is when the first textview extends, it pushes the other textview off the screen.

I have not been able to successfully get this to work, here is an example of what's happening:

alt text

As you can see when the first textview gets too long, it then pushes the other text off the screen. I would like it so it wraps but the date textview is also showing. It should also be functional in horizontal view.

Here's the listview adapter code:

<RelativeLayout android:id="@+id/vw1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:descendantFocusability="blocksDescendants" xmlns:android="http://schemas.android.com/apk/res/android">


<TextView android:id="@+id/liName" android:textSize="17sp"
    android:textColor="#333" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:gravity="left"
    android:layout_gravity="left" />
<TextView android:id="@+id/liDate" android:textSize="12sp"
    android:textColor="#666" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:gravity="right"
    android:layout_gravity="right" android:width="60sp" android:layout_toRightOf="@+id/liName" />

<TextView android:id="@+id/liNum" android:textSize="12sp"
    android:textColor="#666" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_below="@+id/liName" />


</RelativeLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

败给现实 2024-10-16 04:21:01

我假设正在推送的文本视图是 liDate 视图。
您需要将其放在布局中的 liName 之前,并将宽度设置为“wrap_content”并将其右对齐。然后将 liName 与“fill_parent”宽度放在它的左侧
所以它看起来像这样:

<RelativeLayout android:id="@+id/vw1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:descendantFocusability="blocksDescendants" xmlns:android="http://schemas.android.com/apk/res/android">


<TextView android:id="@+id/liDate" android:textSize="12sp"
    android:textColor="#666" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:width="60sp" 
    android:layout_alignParentRight="true" />
<TextView android:id="@+id/liName" android:textSize="17sp"
    android:textColor="#333" android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/liDate" />

<TextView android:id="@+id/liNum" android:textSize="12sp"
    android:textColor="#666" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_below="@+id/liName" />

希望这就是你的意思

I am assuming that the text view being pushed is the liDate one.
You need to put this one before the liName in your layout and set the width to "wrap_content" and align it right. Then you lace the liName to the left of it with "fill_parent" width
So it would look like this:

<RelativeLayout android:id="@+id/vw1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:descendantFocusability="blocksDescendants" xmlns:android="http://schemas.android.com/apk/res/android">


<TextView android:id="@+id/liDate" android:textSize="12sp"
    android:textColor="#666" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:width="60sp" 
    android:layout_alignParentRight="true" />
<TextView android:id="@+id/liName" android:textSize="17sp"
    android:textColor="#333" android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/liDate" />

<TextView android:id="@+id/liNum" android:textSize="12sp"
    android:textColor="#666" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_below="@+id/liName" />

Hope this is what you meant

野味少女 2024-10-16 04:21:01

关键是第一个文本视图使用“@+id/”而不是“@id/”
这对我有用:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <TextView
        android:id="@+id/listEventTypeText"
        android:layout_toLeftOf="@+id/listEventDateText"
        android:layout_alignParentLeft="true"
        />
    <TextView
        android:id="@+id/listEventDateText"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignBaseline="@id/listEventTypeText"
        />
    </RelativeLayout>

The key was using "@+id/" for the first textview instead of "@id/"
This worked for me:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <TextView
        android:id="@+id/listEventTypeText"
        android:layout_toLeftOf="@+id/listEventDateText"
        android:layout_alignParentLeft="true"
        />
    <TextView
        android:id="@+id/listEventDateText"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignBaseline="@id/listEventTypeText"
        />
    </RelativeLayout>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文