0

I want to display Text left and below image.

+---------------------------+
| Text................ Image|
+.......(remain text)........+
Ahmed Mohammed
  • 337
  • 3
  • 16

2 Answers2

0

You can do this in the Layout xml file, Just add to the ImageView this attribute:

android:layout_toRightOf="@id/text" 

this will make it to the right of the Text, and then to make distance between them use this attribute:

android:layout_marginRight="70dp"

And for the Other text use instead of toRightOf - android:layout_below="@id/text" and then keep distance from the starting of the screen using marginRight again.. assign this with the correctly ID's of the texts and Images.

EDIT WITH POSSIBLE CODE:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Text"
            android:id="@+id/textView" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:src="@android:drawable/alert_dark_frame"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New Text"
            android:id="@+id/textView2"
            android:layout_below="@+id/imageView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />





    </RelativeLayout>
</LinearLayout>
DavidBalas
  • 333
  • 7
  • 21
0

i used this code

String text = getResources().getString(R.string.text);
SpannableString ss = new SpannableString(text);
ss.setSpan(new MyLeadingMarginSpan2(6, 230), 0, ss.length(), 0);

TextView textview = (TextView) view.findViewById(R.id.descriptionTextView);
textview.setText(ss);

class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 {
    private int margin;
    private int lines;

    MyLeadingMarginSpan2(int lines, int margin) {
        this.margin = margin;
        this.lines = lines;
    }

    @Override
    public int getLeadingMargin(boolean first) {
        if (first) {
            return margin;
        } else {
            return 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) {}
    @Override
    public int getLeadingMarginLineCount() {
        return lines;
    }
}
Ahmed Mohammed
  • 337
  • 3
  • 16