I have a TableLayout with cells of ImageView
s. What I am trying to do is create a zooming effect by incrementing the size of the ImageView
s in the tabel. This works perfectly for zooming out( the picture resizes with the ImageView
) but, the problem is with zooming in. The picture does not resize when the ImageView
is made bigger.
Here is an example:
I want the image to be the same size as the ImageView(each black square is an ImageView)
Here is my code for the zooming ( any tips on better implementation would be appreciated, don't want to use pinch zoom ).
zoomIndex ranges from -2, 2. (only allow them to zoom twice in each direction)
zoomInThreshold = 2, zoomOutThreshold = -2.
defaultSize = 50, zoomIncrement = 15;
if(zoomIndex < zoomInThreshold)
defaultSize += zoomIncrement;
for(int i = 0; i < table.getChildCount(); ++i)
{
TableRow row = (TableRow)table.getChildAt(i);
for(int r = 0; r < row.getChildCount(); ++r)
{
ImageView img = (ImageView)row.getChildAt(r);
if(zoomIndex < zoomInThreshold)
{
TableRow.LayoutParams imgLayoutParams = new TableRow.LayoutParams(
defaultSize,
defaultSize
);
img.setLayoutParams(imgLayoutParams);
if(img.getDrawable() != null)
{
img.setAdjustViewBounds(true);
img.setMaxHeight(defaultSize);
img.setMaxWidth(defaultSize);
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
}
}
}
}
if(zoomIndex < zoomInThreshold)
zoomIndex++;