1

does anyone know if this is possible to do in android?

enter image description here

I tried aligning the description text to the right of the 50p text but it will just write the next line of text aligned to the bottom right of the 50p text instead of underneath it wrapped around.

 <TextView
        android:id="@+id/product_points_text"
        style="@style/TitleTextAppearance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/default_margin"
        android:layout_marginTop="@dimen/small_margin"
        app:layout_constraintTop_toBottomOf="@id/product_image"
        tools:text="+40" />


    <TextView
        android:id="@+id/description_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="@dimen/default_margin"
        android:layout_marginTop="@dimen/default_margin"
        app:layout_constraintLeft_toRightOf="@id/product_points_text"
        app:layout_constraintTop_toBottomOf="@id/product_image"
        tools:text="Description of product offer goes here!!!!!" />
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Jono
  • 17,341
  • 48
  • 135
  • 217

2 Answers2

0

You can try using SpannableStringBuilder:

SpannableStringBuilder str = new SpannableStringBuilder("some string");
str.setSpan(new AbsoluteSizeSpan(SIZE, true), start, stop, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

And place everything in one TextView.

Edit:

For different features see:

Android: Coloring part of a string using TextView.setText()?

set Style:

str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, stop, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

etc.

Source: https://developer.android.com/reference/android/text/style/AbsoluteSizeSpan.html

muminers
  • 1,190
  • 10
  • 19
  • also. can the selected spannable text be a different color, font or style? – Jono Mar 09 '18 at 12:10
  • 1
    Well String.format output is just a String, so if you create SpannableStringBuilder(String.format(...)) than I'd guess it will work fine. And about color, style, etc - yes, with ease. https://stackoverflow.com/questions/4897349/android-coloring-part-of-a-string-using-textview-settext – muminers Mar 09 '18 at 12:41
0

Try this:

<TextView
android:id="@+id/product_points_text"
style="@style/TitleTextAppearance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/default_margin"
android:layout_marginTop="@dimen/small_margin"
app:layout_constraintTop_toBottomOf="@id/product_image"
tools:text="+40" />


<TextView
    android:id="@+id/description_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_constraintTop_toRightOf="@+id/product_points_text"
    android:layout_constraintTop_toEndOf="@+id/product_points_text"
    android:layout_marginLeft="@dimen/default_margin"
    android:layout_marginTop="@dimen/default_margin"
    tools:text="Description of product offer goes here!!!!!" />
Red M
  • 2,609
  • 3
  • 30
  • 50