将视图的大小调整为其内容

时间:2014-10-16 12:06:40

标签: android

我有一个自定义视图类,可以将位图绘制到视图中

 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
            super.onSizeChanged(w, h, oldw, oldh);

            Log.d("Log","Called with w and h " + w +"," + h);

            // method called multiple times but initialized just once
            if (wheelHeight == 0 || wheelWidth == 0) {

                wheelHeight = h;
                wheelWidth = w;
                // resize the image
                Matrix resize = new Matrix();
                resize.postScale((float)0.60, (float)0.60);



                imageScaled = Bitmap.createBitmap(imageOriginal, 0, 0, imageOriginal.getWidth(),
                        imageOriginal.getHeight(), resize, false);
                // translate the matrix to the image view's center
                float translateX = wheelWidth / 2 - imageScaled.getWidth() / 2;
                float translateY = wheelHeight / 2 - imageScaled.getHeight() / 2;
                matrix.postTranslate(translateX, translateY);
                WheelMenu.this.setImageBitmap(imageScaled);
                WheelMenu.this.setImageMatrix(matrix);

 //This has no affeect on the height of the view
               setMinimumHeight(imageScaled.getHeight());


                Log.d("Image","the height of the control is" +getHeight());
                Log.d("Image","the height of the bitmap is" +imageScaled.getHeight());

            }

        }

我要做的是将视图的高度更改为位图的高度。设置其高度不会影响视图。我做错了什么?

亲切的问候

0 个答案:

没有答案