java - Issue with stroke in text, Android -


intent of text stroke here can see problem is, made custom textview in android, add stroke scores. far i'm having 2 separated texts instead of 1 stroke...

here code:

xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/game_end_share_relative_main"     android:layout_width="@dimen/share_width"     android:layout_height="@dimen/share_height"     android:background="#000000" >              <com.sharing.stroketextview                 android:id="@+id/user_share_points"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="3"                 android:textcolor="@color/primary"                 android:layout_marginright="16dp"                 style="@style/secondaryfontfamily"                 android:textsize="70dp" /> 

and custom textview:

public class stroketextview extends textview { private int mstrokecolor; private int mstrokewidth; private textpaint mstrokepaint;  public stroketextview(context context, attributeset attrs, int defstyle) {     super(context, attrs, defstyle);     init(attrs); }  public stroketextview(context context, attributeset attrs) {     super(context, attrs); }  public stroketextview(context context) {     super(context); }  public void setstrokecolor(int color) {     mstrokecolor = color; }  public void setstrokewidth(int width) {     mstrokewidth = width; }  @override protected void ondraw(canvas canvas) {     if (mstrokepaint == null) {         mstrokepaint = new textpaint();     }      mstrokepaint.settextsize(gettextsize());     mstrokepaint.settypeface(gettypeface());     mstrokepaint.setflags(getpaintflags());      mstrokepaint.setstyle(paint.style.stroke);     mstrokepaint.setcolor(mstrokecolor);     mstrokepaint.setstrokejoin(paint.join.round);     mstrokepaint.setstrokecap(paint.cap.round);     mstrokepaint.setstrokewidth(mstrokewidth);     mstrokepaint.setshadowlayer(2.0f, 5.0f, 5.0f, color.black);      mstrokepaint.settypeface(typeface.createfromasset(getcontext().getassets(), "fonts/mikadoblack.otf"));     string text = gettext().tostring();     canvas.drawtext(text, getwidth() - (mstrokepaint.measuretext(text) / 2),  getbaseline(), mstrokepaint);     super.settypeface(typeface.createfromasset(getcontext().getassets(), "fonts/mikadoblack.otf"));     super.ondraw(canvas); }  } 

thanks in advance :)

jose

this because drawtext in super class drawing @ different position yours. try setting content gravity 'center' using view.setgravity(gravity.center) may solve problem. also, if using padding on view need factor in while calculating origin drawtext method

 int hpadding = getpaddingleft()+getpaddingright();  int contentareawidth = getwidth() - hpadding;  canvas.drawtext(text, contentareawidth - (mstrokepaint.measuretext(text) / 2), getbaseline(), mstrokepaint); 

this in aligning stroked text normal text drawn in super class.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -