Search code examples
androidtextview

Position textView and control its width and height


How can I customize the TextView and position it there so that it only covers a selected part of the screen as in the link?

(source: mediafire.com)

http://www.mediafire.com/view/0r389nv7ynb3yu0/Screenshot_2015-04-18-23-58-14+-+Copy+%282%29.png#

The snapshot is drawn using Paint. I have the x, y coordinates as well of the rectangle shown in the link but how can I do this with textView


Solution

  • If I understood the question correctly, this should do it.

    Give it a height and width using dp, then use "align" and then margin.

    Example:

    <TextView android:text="@string/hello_world"
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"/>