The Responsibility of a Data Engineer

Wondering about what is a Data Engineer? In this post, we go through the evolution of this role and how it relates to other roles in the data science field.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Creating the Twitter image Display layout with recycler view

Recycler view is a trendy and important view in Android development, and it is a very wonderful view to use. I am going to take you through how it's done in Android development.

For my simple screen, I just have a button to select the images and a recycler view to display the selected images.

For this project ill be using view binding for my layouts so let us add this to our build.gradle app

With this addition, our MainActicity.kt will look like this

Now, this is where it all gets interesting. Let's recall that we want to implement the image display the way Twitter displays their images when we have one image it fills the entire view, when it is two images we see that the view is divided into two equal vertical parts, and when its three it divides the left part of the view into two horizontal parts. We will create all different screens to give us the look and feel of this effect.

First, we design the XML for one image and it will look like this

The layout for displaying two images will look like this.

And finally, the view displaying three images will look like this

We are going to add the style to curve the edges of the image views to complete the look. That means the in our themes.xml file we add the following styles

Now in this step, we are going to create our recycler view adapter using ListAdapter which is more powerful than our RecyclerView.Adapter class with multiple ViewHolders for our different number of images. Here is our Adapter

Talking about the benefits of this Adapter over RecyclerView.Adapter is beyond the scope of this article but you can get all the juicy bits in another article.

Having that in place here is our Different Viewholders using Viewbinding.

Now we include the Logic for altering our ViewHolders based on the size of our list

Now before we move to the next step it’s important to note two things:

Now let's go to our MainActivity.kt and finish up this amazing setup.

We need to do a couple of things here so we can finish things up

Starting at API 19 android apps are needed to have Runtime permissions in their app so here is ours

2. Fire-up the intent to get the images from our android device when our permissions have been granted

3. Now we override on Activity result to receive the list of images from our gallery

Finally, we pass the results to a function that will set up our recycler view, and Voila we are done

Now here is our result

Add a comment

Related posts:

7 questions on Open Banking

He sits cross-legged in the armchair. Gently swirling a tumbler of scotch and rocks, he’s entranced with a brooding expression. Richard Shanahan is, above all else, a tall man. When he’s not deep in…

Something to See Here

I very intentionally didn’t learn much about this book before reading it. In fact I was so circumspect about this book before first diving in that I didn’t even know it was fiction. This was very…

Lessons to turn a ship around

I recently finished ready David Marquet’s book “Turning the ship around” . It’s an interesting real-life tale of a submarine captain that completely change the culture of his team. Instead of the…