Reputation: 7456
I'm trying to align the top of a TextView (which will always be an integer greater than 0) and an ImageView.
Padding the top of the Imageview by 4dp
was very close, but it is an inexact solution.
The culprit is this:
Disregard the padding to the left. The padding above the number and below the number are frustrating. Is there any way to have the top and bottom completely wrap around the number? I suppose the issue will come from 4, 5, 6, 8, 9, etc. potentially having different upper limits, but is there a way to handle this? android:includeFontPadding=false
gets rid of something of the padding, but it doesn't get rid of it all.
XML:
<TextView
android:id="@+id/commentsCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:layout_marginRight="4dp"
android:textColor="@color/blue"
android:visibility="visible"
android:text="4"/>
<ImageView
android:id="@+id/commentsCountBubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_comment_bubble"
android:visibility="visible"
/>
Wrapped in a standard LinearLayout.
Edit: Also note that the padding around the Imageview wraps the content completely (basically, there is no padding).
Upvotes: 0
Views: 294
Reputation: 2057
Try this:
<TextView
android:id="@+id/commentsCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_launcher"
android:drawablePadding="8dp"
android:layout_marginRight="4dp"
android:textColor="@color/blue"
android:visibility="visible"
android:text="4"/>
Upvotes: 2
Reputation: 2969
If your views are placed on RelativeLayout
you can use that on your TextView
:
android:layout_alignTop="@+id/yourImageView"
Good luck.
Upvotes: 0