如何获得并排文本视图与换行文本视图
我有一个带有自定义适配器的 listview
,其中有 3 个 textview
,其中两个彼此相邻,一个位于其他视图下方。我遇到的问题是,当第一个 textview
扩展时,它将另一个 textview
推离屏幕。
我无法成功地使其工作,这是发生的情况的示例:
正如您所看到的,当第一个 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 textview
s, 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设正在推送的文本视图是 liDate 视图。
您需要将其放在布局中的 liName 之前,并将宽度设置为“wrap_content”并将其右对齐。然后将 liName 与“fill_parent”宽度放在它的左侧
所以它看起来像这样:
希望这就是你的意思
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:
Hope this is what you meant
关键是第一个文本视图使用“@+id/”而不是“@id/”
这对我有用:
The key was using "@+id/" for the first textview instead of "@id/"
This worked for me: