Android ListView 中的文本被截断
我知道论坛上有很多类似的问题,但很多情况都是独一无二的,所以这里是。
我有一个自定义列表视图,它根据应用程序主题以不同的方式显示“事件”。标题、替代文本和标签的文本都被切断(无论高度设置为多少)。你能帮我解决这个问题吗?
文本在我的 3 个主题中的两个中被截断,并且仅在实际设备(不是模拟器)上被截断。
每个列表项的代码非常相似,因此我仅在下面附加一个(如果需要,将附加其他的);谢谢。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<!-- ?android:attr/listPreferredItemHeight -->
<LinearLayout android:id="@+id/viewrow_flags"
android:orientation="vertical" android:layout_width="36px"
android:layout_height="80px" android:layout_marginRight="6dip">
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="fill_parent">
<TextView android:id="@+id/viewrow_toptext"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:singleLine="true" android:layout_weight="1" android:gravity="center_vertical"
android:textColor="#00ccFF" android:textSize="6pt" android:paddingBottom="1dip"/>
<TextView android:layout_width="fill_parent" android:gravity="center_vertical"
android:layout_height="fill_parent" android:layout_weight="1"
android:id="@+id/viewrow_bottomtext" android:textColor="#0066FF"
android:singleLine="true" android:textSize="6pt" android:paddingBottom="1dip"/>
<TextView android:layout_width="fill_parent" android:gravity="center_vertical"
android:layout_height="fill_parent" android:layout_weight="1"
android:id="@+id/viewrow_tagtext" android:textColor="#0066FF"
android:singleLine="true" android:textSize="6pt" android:paddingBottom="1dip"/>
</LinearLayout>
<View android:id="@+id/viewrow_anchor" android:layout_width="0sp"
android:layout_height="60dip" android:layout_gravity="center" />
<TextView android:id="@+id/viewrow_dayview"
android:layout_width="60sp" android:layout_height="80px"
android:gravity="center" android:paddingLeft="6dip"
android:paddingTop="12dip" />
</LinearLayout>
I know there are a lot of questions like this on the forums, but many cases are unique, so here goes.
I have a custom list view that displays an "event" in different ways based on the application theme. The text for the title, alt-text and tags are all getting cut off (regardless of what the height is set to). Can you please help me fix the problem?
The text is cut off in two of my 3 themes, and only on the actual device (not emulator).
The code for each list item is very similar, so I'm attaching only one below (and will attach the others if needed); thanks.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<!-- ?android:attr/listPreferredItemHeight -->
<LinearLayout android:id="@+id/viewrow_flags"
android:orientation="vertical" android:layout_width="36px"
android:layout_height="80px" android:layout_marginRight="6dip">
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="fill_parent">
<TextView android:id="@+id/viewrow_toptext"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:singleLine="true" android:layout_weight="1" android:gravity="center_vertical"
android:textColor="#00ccFF" android:textSize="6pt" android:paddingBottom="1dip"/>
<TextView android:layout_width="fill_parent" android:gravity="center_vertical"
android:layout_height="fill_parent" android:layout_weight="1"
android:id="@+id/viewrow_bottomtext" android:textColor="#0066FF"
android:singleLine="true" android:textSize="6pt" android:paddingBottom="1dip"/>
<TextView android:layout_width="fill_parent" android:gravity="center_vertical"
android:layout_height="fill_parent" android:layout_weight="1"
android:id="@+id/viewrow_tagtext" android:textColor="#0066FF"
android:singleLine="true" android:textSize="6pt" android:paddingBottom="1dip"/>
</LinearLayout>
<View android:id="@+id/viewrow_anchor" android:layout_width="0sp"
android:layout_height="60dip" android:layout_gravity="center" />
<TextView android:id="@+id/viewrow_dayview"
android:layout_width="60sp" android:layout_height="80px"
android:gravity="center" android:paddingLeft="6dip"
android:paddingTop="12dip" />
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现了问题,它是布局重量和整体视图列表项高度的混合。
I figured out the problem, it was a mixture of layout weight and overall view list item height.
您将 TextView 定义为带有 android:singleLine="true" 的单行。因此,如果文本对于空间来说太大,则会被裁剪。将 TextView 设置为允许文本换行并扩展其高度,或者您可以使用 android:ellipsize="marquee" 属性在单行上显示文本。
You have your TextViews defined as single lines with android:singleLine="true". So, if the text is too big for the space, it will be cropped. Either set the TextViews up to allow for wrapping of texting and expanding their height OR you could use the android:ellipsize="marquee" attribute to display the text on a single line.
被切断的添加
android:layout_weight="1"
add
android:layout_weight="1"
to those who are cut off只需将线性中的layout_height =“fill_parent”更改为wrap_content
just change layout_height="fill_parent" in linear to wrap_content