开发者

second onSizeChanged gets height of zero

I have an app that displays some data graphically. It creates two Views to draw graphics in and adds them to my layout. Each view shows the data differently way 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);
    }

The views are invoked thusly:

      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 gets called gets a height of 652 and a width of 480; the second one gets a height of 0, which causes cr开发者_JAVA百科eateBitmap() to fail. If I reversed the order of the above invocation then graphView1 would fail that way. I'd like each bitmap to have about half the area.

Thanks in advance for explaining what's going on!


its difficult to answer your question without knowing further implementation details about your graphviews and the layout parameters of the LinearLayout. But assuming your LinearLayout has a horizontal orientation try this:

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));

this will tell the LinearLayout to arrange your views so that they equally divide the horizontal space between themselves.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜