android - Adding text to a custom TextView is not visible -


hi have problem custom textview.i trying add text custom textview programmatically,but, not appear

mainactiviy:

public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         linearlayout container1 = (linearlayout) findviewbyid(r.id.container1);         linearlayout container2 = (linearlayout) findviewbyid(r.id.container2);          animview = new myanimationview(this);                    animview.setminimumwidth(200);         animview.setminimumheight(200);         animview.settext("xxxxx");         animview.setlayoutparams(new linearlayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content,1f));         container1.addview(animview); 

and customview class inner class of mainactivity is

public class myanimationview extends textview implements valueanimator.animatorupdatelistener {      public final arraylist<shapeholder> balls = new arraylist<shapeholder>();     public final arraylist<rectholder> rects = new arraylist<rectholder>();     animatorset animation = null;     animatorset clickanimation=null;     private float mdensity;     public canvas can=new canvas();     public myanimationview(context context) {         super(context);         mdensity = getcontext().getresources().getdisplaymetrics().density;         shapeholder ball0 = addball(50f, 200f);         rectholder newline = addline(40f,150f);      }      public void beginanimation(int pos) {         createselectionanimation(pos);         clickanimation.start();       }      private void createselectionanimation(int pos) {         clickanimation=new animatorset();         animation anim=animationutils.loadanimation(getbasecontext(), r.animator.scale);         if(pos==1)             animview.startanimation(anim);         else if(pos==2)             animview1.startanimation(anim);         else if(pos==3)             animview2.startanimation(anim);         else             animview3.startanimation(anim);         objectanimator animalpha = objectanimator.offloat(balls.get(0), "alpha",                 1.0f, 0.0f).setduration(500);         objectanimator animrect = objectanimator.offloat(rects.get(0), "alpha",                 1.0f, 0.0f).setduration(500);         clickanimation.playtogether(animrect,animalpha);         animalpha.addupdatelistener(this);         animrect.addupdatelistener(this);     }      private void createanimation() {         if (animation == null) {             objectanimator anim1 = objectanimator.offloat(balls.get(0), "y",             balls.get(0).gety(), balls.get(0).gety()-200f).setduration(2000);             animation = new animatorset();             animation.playtogether(anim1);             anim1.addupdatelistener(this);         }     }      private shapeholder addball(float x, float y) {         ovalshape circle = new ovalshape();         circle.resize(90f * mdensity, 150f * mdensity);         shapedrawable drawable = new shapedrawable(circle);         shapeholder shapeholder = new shapeholder(drawable);         shapeholder.setx(x);         shapeholder.sety(y);         int red = (int)(100 + math.random() * 155);         int green = (int)(100 + math.random() * 155);         int blue = (int)(100 + math.random() * 155);         int color = 0xff000000 | red << 16 | green << 8 | blue;         paint paint = drawable.getpaint(); //new paint(paint.anti_alias_flag);         int darkcolor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;         gradient = new radialgradient(37.5f, 32.5f,                 110f, color, darkcolor, shader.tilemode.clamp);         paint.setshader(gradient);         shapeholder.setpaint(paint);         balls.add(shapeholder);         return shapeholder;     }      private rectholder addline(float x,float y) {         rectshape rect=new rectshape();         rect.resize(10f * mdensity, 15f * mdensity);         shapedrawable drawable = new shapedrawable(rect);         rectholder rectholder = new rectholder(drawable);         rectholder.setx(x);         rectholder.sety(y);         //can.drawline(45, 150f,45f,160f, paint1);           int red = (int)(100 + math.random() * 155);         int green = (int)(100 + math.random() * 155);         int blue = (int)(100 + math.random() * 155);         int color = 0xff000000 | red << 16 | green << 8 | blue;         paint paint = drawable.getpaint(); //new paint(paint.anti_alias_flag);         int darkcolor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;         gradient = new radialgradient(37.5f, 32.5f,                 110f, color, darkcolor, shader.tilemode.clamp);         paint.setshader(gradient);         rectholder.setpaint(paint);                  rects.add(rectholder);         return rectholder;     }      @override     protected void ondraw(canvas canvas) {         shapeholder shapeholder = balls.get(0);         rectholder rectholder=rects.get(0);         paint paint =getpaint();         paint.settextsize(20f);         paint.setcolor(color.parsecolor("#aaffee"));         paint.setstrokewidth(10f);         paint.setshader(gradient);             canvas.save();                          canvas.translate(shapeholder.getx(), shapeholder.gety());                             shapeholder.getshape().draw(canvas);                  canvas.translate(rectholder.getx(), rectholder.gety());                     rectholder.getshape().draw(canvas);             canvas.restore();           }      public void startanimation() {         createanimation();         animation.start();     }      public void onanimationupdate(valueanimator animation) {         invalidate();     }  } 

please me in this.

call super.ondraw() first in myanimationview.ondraw() method.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -