ListView内的CustomView内的TextView是水平截断的

时间:2013-06-11 14:49:34

标签: android listview custom-view

我在" LabeledTextView"中使用了TextView。 component(基本上是一个TextView,当处理由于从右到左语言导致的布局更改时,其标签从一侧移动到另一侧)。我在ListView中使用它并且发生这种情况:

enter image description here

文本的最后一行是水平截断的。这可能是Android的TextView onMeasure()中的一个错误吗?

同样的" LabeledTextView"组件在其他情况下使用并且工作正常,因此我认为这与它与ListView之间的交互有关。

列表项xml的相应部分如下所示:

<LinearLayout
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="400dp"
    android:orientation="vertical" >

    <com.test.library.view.LabeledTextView
        android:id="@+id/sender"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        custom:label="@string/sender"
        custom:labelWidth="130dp"/>      

    <com.test.library.view.LabeledTextView
        android:id="@+id/message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        custom:label="@string/message"
        custom:labelWidth="130dp"/>                

</LinearLayout>

您可以看到,在包含LinearLayout的过程中,我确保容器的高度不会缩小尺寸。

自定义视图将LayoutParams设置为WRAP_CONTENT的高度 - 您可以看到它已经几乎正确的大小。

修改

但是,当手动增加LabeledTextView的大小时,TextView显示正确,因此我认为我的自定义视图的默认onMeasure()并未正确计算TextView孩子的身高。

1 个答案:

答案 0 :(得分:0)

为显示答案所需的两列使用不同的线性布局。

即。一个用于发件人,另一个用于消息