Reputation: 23
I've got a task to display N*N matrix in Android app.
Numbers in this matrix should be in the specific order, like this: matrix example image
The main trouble is that i should display each cell of matrix with animation with some delay (matrix shouldn't be visible at first and then cells appear, one by one).
How can i achieve this kind of effect? Should I use GridView with custom adapter, or I should create my own view by extending "View" class? Thanks in advance.
Upvotes: 1
Views: 868
Reputation: 8095
I'm not sure how large your matrix will get but I'd recommend you implement this using a RecyclerView
with a GridLayoutManager
, especially if your grid matrix may have variable number of elements.
In a simplified overview, you can achieve this by creating a RecyclerView
in your layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
And then in your the Activity
, apply the GridLayoutManager
to this RecyclerView
which will place each cell (which you will also need to define using a layout and inflating it in the RecyclerView
's onBind
method) in a grid layout as you'd like.
I suggest you see this Stack Overflow post that explains pretty much exactly how to achieve this.
For animations, you can get access to each cell's View
via the RecyclerView.Adapter
that you will define (see the aforementioned post). You probably will want to start each cell with visibility
set to gone
or invisible
then reveal them however you'd like.
If you know your grid size is fixed and relatively small, you could still use a GridLayout
which will spare you all the adapter code for RecyclerView
.
Let me know if you're still having trouble understanding, hope this helps!
Upvotes: 2