1

I have TextView and custom view called StarRating.

There is code snippet:

<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>

Actual Result: enter image description here

Expected Result:

enter image description here

The problem is that TextView is not wrapping the StarRating...

How can I do that ?

VLeonovs
  • 2,193
  • 5
  • 24
  • 44
  • use `LeadingMarginSpan.LeadingMarginSpan2` in your `TextView` – pskink Apr 19 '16 at 13:03
  • The only idea which comes to my mind is to give textview android:layout_width="match_parent" android:layout_height="match_parent", put before your text whitespaces which would create non-text area needed for starsview, before that you need to calculate how much space would be needded. Another option is to create custom view. – MyWay Apr 19 '16 at 13:11
  • If you want to make specific text start in new line you can use \n in string values :) – Mohamed Apr 19 '16 at 13:51
  • just google for `LeadingMarginSpan.LeadingMarginSpan2 wrap text` – pskink Apr 19 '16 at 14:12

3 Answers3

1

This is not HTML. In standard TextView text is layouted within TextView boundaries (rectangle), so this is working as expected. You cannot make it work differently as these views won't work that way and if they overlap they do not know about this anyway.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

Try using android:gravity="center".

<RelativeLayout
    android:id="@+id/flowtextView"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</RelativeLayout>
Yuchen
  • 30,852
  • 26
  • 164
  • 234
Jaydeep purohit
  • 1,536
  • 17
  • 20
0

Another way to do it is add extra spaces in the beginning of your text. it's a little tricky though.

let me know if you want more details.

Mohammad Zarei
  • 1,773
  • 14
  • 33
  • Please provide details! – VLeonovs Apr 19 '16 at 13:11
  • if rating view is clickable then most probably with this way textview will overlap rating bar making it unclickable – Vivek Mishra Apr 19 '16 at 13:11
  • @VivekMishra not really, if u use frame layout and rating view will be above textview it will works right. – MyWay Apr 19 '16 at 13:12
  • @MyWay OP edited his answer after my comment. Earlier he said using `Relative Layout` so according to that my point is valid – Vivek Mishra Apr 19 '16 at 13:16
  • I guess both ways are good....frame layout and relative layout – Mohammad Zarei Apr 19 '16 at 13:18
  • I have an idea which not tested yet, but i think by using this [link](http://stackoverflow.com/a/3630331/4310784), u can have your size per character. after that, with having width of each star or whole StartRating view, can calculate necessary spaces to put before your text. – Mohammad Zarei Apr 19 '16 at 13:20