I’m trying to copy some layout xml (which I can’t get to work), but I don’t understand how this works. Its drawing a divider with wrap content, but it has no content so how does it draw?
<TextView
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1px"
android:background="@color/medium_gray"
android:layout_below="@id/spacer"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/gutter_right"
android:layout_toRightOf="@id/image" />
If I had to guess, they put content in it somewhere in the code. They make the background grey, but the height is only 1 pixel high, so if you fill the TextView with blank spaces it will make a grey line that are 1 pixel in height.
Anyway, the constant
wrap_contentmeans that the size of the view is dependent on the content is contains. In the case of aTextView, it will be as big as the characters it has to draw. If you changed it tofill_parentormatch_parent, then the size will be bound based on the dimensions its parent determines.If you did something like this:
Then it will draw a 1 pixel high grey line from the left side of the parent to the right side of the parent subtracting a margin from the right of size
@dimen/gutter_right.There’s no specific reason to use a
TextViewother than its a widget that doesn’t have drawing disabled, thus the background is drawn.