android - Why does transparent stroke display with only half of width? -
i'm trying use <shape>
displaying pressed state of button. that, use stroke transparent color in normal state , colored 1 in pressed state:
button.xml :
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/button_normal"/> </selector>
button_pressed.xml :
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#0f0" /> <stroke android:width="@dimen/size_medium" android:color="#f00" /> <padding android:left="@dimen/size_medium" android:top="@dimen/size_medium" android:right="@dimen/size_medium" android:bottom="@dimen/size_medium" /> </shape>
button_normal.xml :
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#00f" /> <stroke android:width="@dimen/size_medium" android:color="#0000" /> </shape>
and in testing layout :
<button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/action_sign_in" android:textstyle="bold" android:layout_margintop="16dp" android:background="@drawable/button" android:textcolor="#ffffff" android:textalignment="viewstart" android:textappearance="@null" android:textsize="15sp" android:enabled="true"/>
p.s. question: why padding used both of states if set in pressed one?
the stroke split evenly on either side of stroke path. if there way "peel back" red outline on second image, you'd see green box exact same size blue box in first image. , think "padding" in first image part of transparent stroke.
try experiment: make stroke color translucent rather transparent, , you'll able see how stroke straddles halfway onto shape.
it doesn't though there way in shape xml specify stroking inside or outside of shape, if that's need, might have own canvas.draw()
calls in code.
Comments
Post a Comment