gpt4 book ai didi

Android Coverflow - 聚焦位置已知的图像

转载 作者:行者123 更新时间:2023-11-29 13:58:57 24 4
gpt4 key购买 nike

我已经实现了 Android Coverflow 示例。单击图像时,我可以检索它的位置并在 ImageView 中显示图像。我的另一个要求是在我传递其 Id 时将图像聚焦在 coverFlow 中。我应该把聚焦的图像带到中心。这是在转换过程中计算图像之间角度的代码。我怎样才能改变它以获得所需的输出?

 protected boolean getChildStaticTransformation(final View child, final Transformation t) {

final int childCenter = getCenterOfView(child);
final int childWidth = child.getWidth();
int rotationAngle = 0;

t.clear();
t.setTransformationType(Transformation.TYPE_MATRIX);

if (childCenter == mCoveflowCenter) {
transformImageBitmap((ImageView) child, t, 0);
} else {
rotationAngle = (int) ((float) (mCoveflowCenter - childCenter) / childWidth * mMaxRotationAngle);
if (Math.abs(rotationAngle) > mMaxRotationAngle) {
rotationAngle = rotationAngle < 0 ? -mMaxRotationAngle : mMaxRotationAngle;
}
transformImageBitmap((ImageView) child, t, rotationAngle);
}

return true;
}


private void transformImageBitmap(final ImageView child, final Transformation t, final int rotationAngle) {
mCamera.save();
final Matrix imageMatrix = t.getMatrix();

final int height = child.getLayoutParams().height;

final int width = child.getLayoutParams().width;
final int rotation = Math.abs(rotationAngle);

mCamera.translate(0.0f, 0.0f, 100.0f);

// As the angle of the view gets less, zoom in
if (rotation < mMaxRotationAngle) {
final float zoomAmount = (float) (mMaxZoom + rotation * 1.5);
mCamera.translate(0.0f, 0.0f, zoomAmount);
}

mCamera.rotateY(rotationAngle);
mCamera.getMatrix(imageMatrix);
imageMatrix.preTranslate(-(width / 2.0f), -(height / 2.0f));
imageMatrix.postTranslate((width / 2.0f), (height / 2.0f));
mCamera.restore();
}

最佳答案

您可以使用 coverFlow 的 setOnItemSelectedListener 实现此目的。请参阅下面的代码,您可以在其中获取中心图像的位置。

int sel_pos;

coverFlow.setOnItemSelectedListener(new SelectListener(this));

private class SelectListener implements AdapterView.OnItemSelectedListener {

public SelectListener(Context c)
{

}

public void onItemSelected(AdapterView<?> parent, View v, int position,long id)
{

Log.e("Changed----->", "" + position);

// Zoom the new selected view
try
{
sel_pos = position;
coverImageAdapter.notifyDataSetChanged();

} catch (Exception animate)
{

}

}

public void onNothingSelected(AdapterView<?> parent) {
}

}

现在,您可以在适配器的 getview 方法中更改 coverFlow 中图像的焦点。

public View getView(int position, View convertView, ViewGroup parent)
{
// Use this code if you want to load from resources
ImageView i = new ImageView(mContext);
i.refreshDrawableState();
Log.e("position==", ""+position);

if(sel_pos==position)
{
i.setImageResource(selectedImage[position]);
}
else
{
i.setImageResource(UnselectedImage[position]);

}


i.setLayoutParams(new CoverFlow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);


// Make sure we set anti-aliasing otherwise we get jaggies
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
return i;

}

希望这对你有帮助。

关于Android Coverflow - 聚焦位置已知的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10598410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com