开发者

Android Text in ListView Is Cut Off

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 开发者_如何学JAVAin 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>


I figured out the problem, it was a mixture of layout weight and overall view list item height.

        <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_weight="1"
+               <TextView android:id="@+id/viewrow_toptext"
                          android:layout_width="fill_parent"                              
                          android:layout_height="fill_parent"
-                         android:singleLine="true" 
                          android:ellipsize="end" 
                          android:gravity="center_vertical"
+                         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:ellipsize="end"
+               <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:ellipsize="end"
+               <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="70dip" 
                      android:layout_gravity="center" />
+                     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"


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.


add android:layout_weight="1" to those who are cut off


just change layout_height="fill_parent" in linear to wrap_content

<LinearLayout android:orientation="vertical"
    android:layout_width="0dip" android:layout_weight="1"
    android:layout_height="fill_parent">
    <TextView android:id="@+id/viewrow_toptext"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜