android - 缩放图库中的选定图像

标签 android gallery

我如何缩放图库中选定的图像,我试过了,但效果不是很好。 `

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/

相关文章:

用于 GEO-URI 的 Android Intent 过滤器

android - 使用物理平板电脑为 Android 平板电脑开发

javascript - Unslider 点大小显得太大

java - 如何将图库中的图像作为文件参数

java - 你能防止一遍又一遍地编写带有微小差异的代码吗?

android - Firestore 安全规则 : PERMISSION DENIED when Batching

android - SecurityException 从 Android 库中读取图片

jquery - 响应式图像网格。填写包裹上的空白

html - 居中 <ul> 标签

android - 请告诉我有关Java移动应用程序的信息