开发者

Dynamically change size of GridView

I'm developing an application for android, and i have a big old GridView that's centered vertically in the screen, with all the cells visible.

What i want, is a function by which all cells are zoomed in by a factor of 3, letting the user scroll around in the gridview instead.

Sort of how Wordfeud does it if you're familiar with the game.

I've searched the webs and haven't found a satisfactory solution, i managed to f开发者_开发技巧ind a way to alter the layout params in my adapter for the grid tiles, but it only stretches them vertically and not horizontally, also the whole app becomes slow and unresponsive until you've scrolled through the list and let the Grid reload all the views or whatever.

Any help at all is appreciated.


In the end, i used a custom view with a Canvas instead - much easier than trying to bend GridView into something it's not supposed to be.


I know it's been a while since you asked, but I had a similar problem that it took me a long time to solve, so I'm hoping someone else may stumble on this. I ended up extending the GridLayout class and hooking up an instance of

private class ScaleGestureListener
    extends ScaleGestureDetector.SimpleOnScaleGestureListener

in the constructor:

        scaleDetector = new ScaleGestureDetector(context, new ScaleGestureListener());

since it's a view group, override the dispatch… instead of the on… methods:

     @Override
     public boolean dispatchTouchEvent(MotionEvent ev){
         scaleDetector.onTouchEvent(ev); 
         super.dispatchTouchEvent(ev);
         return true;
     }

    @Override
    public void dispatchDraw(Canvas canvas) {
        String disp = String.valueOf(mScaleFactor);
        Log.v(TAG, "dispatch draw " + disp);

        canvas.save();
                 // i have some other stuff in here specific to my app 
        canvas.scale(mScaleFactor, mScaleFactor);
        super.dispatchDraw(canvas);
        canvas.restore();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜