【发布时间】:2014-06-27 22:43:09
【问题描述】:
我有一个带有ImageViews 单元格的表格布局。我要做的是通过增加表格中ImageViews 的大小来创建缩放效果。这非常适合缩小(使用ImageView 调整图片大小)但是,问题在于放大。当ImageView 变大时,图片不会调整大小。
这是一个例子:
我希望图像与 ImageView 大小相同(每个黑色方块都是一个 ImageView)
这是我的缩放代码(任何关于更好实施的提示将不胜感激,不要使用捏缩放)。
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++;
【问题讨论】:
-
你应该为此提供赏金:)
-
我只能在 2 天内开始赏金
标签: android imageview tablelayout scaletype