0

I would like to know if there is an easy way of having a grid of elements, where when one of the elements is pressed,

This state:

http://i.imgur.com/IB4vIvF.png

Changes, to reveal the touched element (center element here)

http://i.imgur.com/6y4nriR.png

For a start, I thought manually re-adding the element as over all others, then programmatically setting the position to keep it appear to be centered.

Is there an easier way, or do I have to break a bit of sweat for it?

EGHM
  • 2,144
  • 23
  • 37
Krisztiaan
  • 31
  • 7
  • If each of the elements in your grid is a layout containing your the blue square (from your image example). You can scale your square within that layout. Let me know if you want me to post a full functional example. – Pol Nov 03 '15 at 21:16
  • Try this http://stackoverflow.com/a/17102241/28557 – Vinayak Bevinakatti Nov 03 '15 at 21:25
  • @VinayakB The linked post has this: http://developer.android.com/training/animation/zoom.html from there, it's almost too easy. Thanks! – Krisztiaan Nov 03 '15 at 21:30
  • Yea, I did suggested you that. I found specific to GridView which you are looking for. The OP is explaining his requirement by pointing to that link though. – Vinayak Bevinakatti Nov 03 '15 at 21:32

1 Answers1

0

As far as I know, Android animations don't affect views boundaries. Therefore, you could simply use setScale method of view to scale them up and down. Also, you could considering animations for better UX.

In Android there are two general way for displaying a grid of views:

  • Grid View
  • Grid Layout

In both approaches, this trick can be used.

  • For each cell (individual views) add a touch listener in which whenever the touch is of type down, scale it up and otherwise scale it to normal.

In Grid Views, you should do this in its adapter while for a grid layout you could iterate over its children and apply this.

frogatto
  • 28,539
  • 11
  • 83
  • 129
  • This is actually more viable than @Vinayak B s solution above, since I can use a custom animation, and it's less of a hassle to do this on multiple views. I started implementing a solution based on your answer, so I'll just mark it as one. Thanks, for the quality and on point reply! – Krisztiaan Nov 04 '15 at 21:04