title: Text wrap around image in fragments
body: <p>Im trying to set wrap text around image in one of my <code>Fragments</code> but it isn't working. Can somebody help me to solve this issue?</p>
  
  <p>code in xml <code>Fragment4</code></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="make.appaplication.Fragment4"&gt;
  
  
  
  &lt;!-- TODO: Update blank fragment layout --&gt;
  
  &lt;ImageView
      android:layout_width="150dp"
      android:layout_height="150dp"
      android:src="@drawable/nature"
      android:id="@+id/imageView"
      android:layout_weight="1"
      android:layout_marginRight="17dp"
      android:layout_marginEnd="17dp"
      android:layout_alignParentTop="true"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true" /&gt;
  
  &lt;TextView
      android:id="@+id/textView3"
      android:textSize="17dp"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="@string/text_page_1"
      android:layout_below="@+id/textView5"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true" /&gt;
  </code></pre>
  
  <p>code in class <code>MyLeadingMarginSpan2</code></p>
  
  <pre><code>    public class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 {
      private int margin;
      private int lines;
      private boolean wasDrawCalled = false;
      private int drawLineCount = 0;
  
      public MyLeadingMarginSpan2(int lines, int margin) {
          this.margin = margin;
          this.lines = lines;
      }
  
      @Override
      public int getLeadingMargin(boolean first) {
          boolean isFirstMargin = first;
          // a different algorithm for api 21+
          if (Build.VERSION.SDK_INT &gt;= 21) {
              this.drawLineCount = this.wasDrawCalled ? this.drawLineCount + 1 : 0;
              this.wasDrawCalled = false;
              isFirstMargin = this.drawLineCount &lt;= this.lines;
          }
  
          return isFirstMargin ? this.margin : 0;
      }
  
      @Override
      public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) {
          this.wasDrawCalled = true;
      }
  
      @Override
      public int getLeadingMarginLineCount()
      {
          return this.lines;
      }
  }
  </code></pre>
  
  <p>and code in class <code>Fragment4</code></p>
  
  <pre><code>String text = getString(R.string.text_page_1);
          SpannableString ss = new SpannableString(text);
          Drawable dIcon = ContextCompat.getDrawable(getActivity(),R.drawable.nature);
          int rightMargin = dIcon.getIntrinsicWidth() + 10;
          ss.setSpan(new MyLeadingMarginSpan2(3, rightMargin), 0, ss.length(), 0);
          final TextView messageView = (TextView) view.findViewById(R.id.textView3);
          messageView.setText(ss);
  </code></pre>
  
  <p>Here is what I have now</p>
  
  <p><a href="https://i.stack.imgur.com/gzaBk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gzaBk.jpg" alt="enter image description here"></a></p>