Android: how to programmatically set width of ImageView inside TableRow

前端 未结 2 1011
闹比i
闹比i 2020-12-09 05:53

How do you programmatically set the width of an ImageView inside a TableRow? I do NOT want the cell width to change, only the width of the image inside the cell.

相关标签:
2条回答
  • 2020-12-09 06:28

    Another way that u resized the bitmap

        ImageView img=(ImageView)findViewById(R.id.ImageView01);
        Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
        int width=200;
        int height=200;
        Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
        img.setImageBitmap(resizedbitmap);
    
    0 讨论(0)
  • 2020-12-09 06:38

    Do you want to scale the image? Or crop it?

    To scale, try ImageView.setImageMatrix and Matrix.preScale.

    If you don't want to figure out the Matrices, you could try Rects (bounding boxes). Get the original rect with ImageView.getDrawingRect and then define whatever Rect you want and use Matrix.setRectToRect to create your image matrix.

    Otherwise, have you tried ImageView.setMaxWidth?

    0 讨论(0)
提交回复
热议问题