android – 在库中缩放选定的图像

我怎样才能缩放图库中的所选图像,我试过这个,但它不能很好地工作. `

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));
        }`

解决方法:

我有同样的问题,有一个类似的解决方案,我将在这里提出堆栈溢出,但它没有正常工作,虽然视图将扩展,他们最终将停止返回其原始大小.

这是我为自己找到的修改后的修复,到目前为止似乎工作正常,并没有引起任何问题.

在res / anim中,创建一个grow.xml文件,将scale size更改为适合您的任何内容

<?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>

复制此类并将其放在继承的库中或您的活动中

    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));  

这对我有用,让我知道它是否适合你.

上一篇:Linux与BSD的区别


下一篇:在Android中的一次滑动中将图库视图移动到下一个图像?