Android textview包装自定义视图

时间:2016-04-19 12:57:33

标签: android

我有TextView和名为StarRating的自定义视图。

有代码段:

<RelativeLayout
    android:id="@+id/flowtextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.app.views.StarRating
        android:id="@+id/star_rating"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/_2sdp"
        android:text="by Legacy Reviewer, April 11, 2014 from Chicago IL"
        android:textSize="12sp"
        android:layout_alignParentTop="true"
        android:layout_toEndOf="@+id/star_rating" />
</RelativeLayout>

实际结果: enter image description here

预期结果:

enter image description here

问题是TextView没有包裹StarRating ...

我该怎么做?

3 个答案:

答案 0 :(得分:1)

这不是HTML。在标准的TextView文本中,在TextView边界(矩形)中进行了布局,因此这是按预期工作的。你不能让它以不同的方式工作,因为这些视图不会以这种方式工作,如果它们重叠,它们无论如何都不知道。

答案 1 :(得分:0)

尝试使用android:gravity="center"

<RelativeLayout
    android:id="@+id/flowtextView"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</RelativeLayout>

答案 2 :(得分:0)

另一种方法是在文本的开头添加额外的空格。虽然这有点棘手。

如果您想了解更多详情,请与我们联系。

相关问题