我如何缩放图库中选定的图像,我试过了,但效果不是很好。 `
public void onItemSelected (AdapterView<?> parent, View v, int position, long id)
{
Animation grow = AnimationUtils.loadAnimation(DetailTvShow.this, R.anim.grow);
Button btn = (Button)findViewById(R.id.button1);
btn.setText("saison "+(position+1));
View sideView = v.findViewById(position + 1);
View sideView1 = v.findViewById(position - 1);
if ((sideView != null)||(sideView1 != null)){
((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(80, 115));
((ImageView)sideView1).setLayoutParams(new `enter code here`Gallery.LayoutParams(80, 115));
}
/* sideView = parent.findViewById(position + 1);
if (sideView != null)
((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(80, 115)); */
v.startAnimation(grow);
v.setLayoutParams(new Gallery.LayoutParams(105, 140));
}`
最佳答案
我遇到了同样的问题,有一个与我将在此处介绍的堆栈溢出解决方案类似的解决方案,但它无法正常工作,尽管 View 会缩放,但它们最终会停止恢复到原始大小。
这是我为自己找到的修改后的修复程序,到目前为止似乎工作正常并且不会导致任何问题。
在 res/anim 中创建一个 grow.xml 文件将缩放大小更改为适合您的大小
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1.0"
android:toXScale="1.075"
android:fromYScale="1.0"
android:toYScale="1.075"
android:duration="150"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fillAfter="true">
</scale>
复制这个类并将其放在您继承的图库中或放在您的 Activity 中
private class SelectListener implements AdapterView.OnItemSelectedListener {
private Animation grow = null;
private View lastView = null;
public SelectListener(Context c) {
grow = AnimationUtils.loadAnimation(c, R.anim.grow);
}
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
// Shrink the view that was zoomed
try { if (null != lastView) lastView.clearAnimation();
} catch (Exception clear) { }
// Zoom the new selected view
try { v.startAnimation(grow); } catch (Exception animate) {}
// Set the last view so we can clear the animation
lastView = v;
}
public void onNothingSelected(AdapterView<?> parent) {
}
}
然后在您创建图库类并附加适配器调用之后
yourGalleryName.setOnItemSelectedListener(new SelectListener(this));
这对我有用,如果对你也有用,请告诉我。
关于android - 缩放图库中的选定图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7879245/