Align Xml Drawable Background To Bottom Of View
I am trying to provide a simple solid-color underline to a TextView header. I want this to be reusable and to work with any view in the future, regardless of height. I am trying to
Solution 1:
This can be achieved using gradientDrawable. Here you go:
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:angle="90"android:startColor="#000000"android:centerColor="@android:color/transparent"android:centerX="0.1" /></shape>
Increase/Decrease centerX
to increase/decrease width of your underline. Change startColor
to change the color of the underline.
Explanation:
angle
is the angle of the gradient. 0 is left to right. 90 is bottom to top.
startColor
is the start color of the gradient. Our angle is 90 so the gradient starts from bottom (and so it appears like an underline)
centerColor
is the centerColor which is transparent.
centerX
is the X position of the gradient as a fraction of the width. Keep it small (<0.1) for a good looking underline. Anything above 0.1 looks bad (nobody is stopping you though!).
Post a Comment for "Align Xml Drawable Background To Bottom Of View"