0
我有一个TableLayout的单元格为ImageView
s。我想要做的是通过增加表格中的ImageView
s的大小来创建缩放效果。这适用于缩小(图片大小调整为ImageView
),但问题在于放大。图片不会在ImageView
变大时调整大小。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天内开始赏金 – john