Sluggish zoom and scroll with GridView in Android

前端 未结 1 1143
北海茫月
北海茫月 2020-12-04 01:18

I\'m creating a custom view derived from GridView. This contains a custom ImageView with zooming and panning functionality. Scroll and zoom functionality is sluggish. If the

相关标签:
1条回答
  • 2020-12-04 01:51

    The simplest and easiest solution I found so far is using a custom FrameLayout:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        View myView1 = new MyFrameLayout(this);
    
        setContentView(myView1);  
    }
    

    Which is implemented as shown below and uses the MyImageView custom control in the first example I posted.

    public class MyFrameLayout extends FrameLayout {
    
        public MyFrameLayout(Context context) {
            super(context);
    
            MyImageView i1 = new MyImageView(context);
    
            this.addView(i1);
    
    
            MyImageView i2 = new MyImageView(context);
    
            LayoutParams lp = new LayoutParams(300, 300);
            lp.leftMargin = 100;
            lp.topMargin = 100;
            lp.gravity = 0;
    
            this.addView(i2, lp);
        }
    }
    

    An alternative solution suggestion I got via twitter from Lawrence D'Olivero. It consists on subclassing View, caching it and using the OnDraw event for composing the scrolling image on a fixed background as his demo here.

    0 讨论(0)
提交回复
热议问题