Second onSizeChanged gets zero height

I have an application that displays some data graphically. He creates two views for drawing graphics and adds them to my layout. Each view shows data differently, but each View implements onSizeChanged () the same:

        protected void onSizeChanged(int curw, int curh, int oldw, int oldh) {
        if (bitmap2 != null) {
            bitmap2.recycle();
        }
        canvas2= new Canvas();
        bitmap2 = Bitmap.createBitmap(curw, curh, Bitmap.Config.ARGB_8888);
        canvas2.setBitmap(bitmap2);
    }

Views are invoked this way:

      LinearLayout myLayout = (LinearLayout)findViewById(R.id.revlay);

      GraphView1 graphView1 = new GraphView1(this, theEventArrayList);
      myLayout.addView(graphView1);  

      GraphView2 graphView2 = new GraphView2(this, theEventArrayList);
      myLayout.addView(graphView2);  

Always the first onSizeChanged () that receives the call gets a height of 652 and a width of 480; the second gets a height of 0, which causes createBitmap () to fail. If I change the order of the above call, then GraphView1 will fail in this way. I would like each bitmap to have about half the area.

Thanks in advance for what happens!

+3
source
1

, LinearLayout. , LinearLayout , :

GraphView1 graphView1 = new GraphView1(this, theEventArrayList);
GraphView2 graphView2 = new GraphView2(this, theEventArrayList);
myLayout.addView(graphView2, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
myLayout.addView(graphView1, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));

LinearLayout , .

0

Source: https://habr.com/ru/post/1789514/


All Articles