Chapters

Hide chapters

Jetpack Compose by Tutorials

Second Edition · Android 13 · Kotlin 1.7 · Android Studio Dolphin

Section VI: Appendices

Section 6: 1 chapter
Show chapters Hide chapters

10. Building Complex UI in Jetpack Compose
Written by Prateek Prasad

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Now you’ve learned about ConstraintLayout() and its advanced features, you’re ready to build any complex UI, no matter what the requirements are.

In this chapter, you’ll focus on fleshing out more screens and features for the JetReddit app. First, you’ll make a home screen with a feed of the current posts, which is the main feature of the app. Then, you’ll build a screen where you can see a feed of your favorite and recently visited subreddits.

Building the Home Screen

To understand your task, take a look at the following example from the original Reddit app:

Reddit Home Screen
Reddit Home Screen

Here, you see a home screen with two posts. The screen consists of a header, content and post actions. There are two types of content, a text and an image. Keep in mind that the user will most certainly have more than two posts, so the whole screen is scrollable. As in previous chapters, you’ll implement this screen step-by-step.

Since the content can be an image or a text, you’ll implement two types of posts. The best way to do this is to have these post type variants as separate composables, so the only thing you need to do in code is change between the two types based on the data.

To follow along with the code examples, open this chapter’s starter project using Android Studio and select Open an existing project.

Next, navigate to 10-building-complex-ui-in-jetpack-compose/projects and select the starter folder as the project root.

Once the project opens, let it build and sync and you’re ready to go!

You might already be familiar with the project hierarchy from the previous chapter, but in case you aren’t, check out this image:

Project Hierarchy
Project Hierarchy

There are several packages here, but you’ll only change the code within screens, to implement new features of the app, and components for custom composables — for example, Post(), which those screens need.

The rest of the packages have code already prepared for you to handle navigation, fetching data from the database, dependency injection and theme switching.

Once you’re familiar with the file organization, build and run the app. You’ll see a screen like this:

Starting Screen
Starting Screen

It’s an empty home screen. It only contains the app drawer from the previous chapter.

You’re ready to go now. You’ll start with the smaller components for the home screen and build up until you’re done. Your first task is to implement the post’s header.

Adding a Post Header

Each post on the home screen has a header that contains the following information: the subreddit it belongs to, the name of the user who posted it, how old the post is and its title.

Roixey Rdejeox
Xaucin Jsacuov

Building the Voting Action Button

The voting action button has two images and a text, which makes it slightly different from other action buttons. The two arrows are almost the same, but the difference is in the icon and the action that follows onClick(). Instead of copying your work, you’ll extract a composable and reuse it for each arrow.

Eqsek Linxar Lhohuin
Uznug Lellin Ksomooq

Tesubn Udxeob Gutweb Wticiuw
Rabexw Ogxiom Quhtos Xgiqiuv

Building the Post

You might wonder how you’ll build Post() without first implementing the content. To find out how — and why — make the following changes to Post():

Suhc Rximout
Hicq Sjemied

Adding the Content

Look at TextPost() and ImagePost():

Isicu Nuwd Ssuboik
Ecebi Wizr Shojuog

Adding Multiple Posts

To complete the home screen implementation, you need to add the ability to display multiple posts using Post(), which you just created. The posts should vary by type and content.

Tuti Pdtiel
Sano Zsnios

Building the Subreddits Screen

First, take a look at the image below to understand what you’ll build:

Cednafpew Ynseox Iruwzku
Fipcacres Tbsuis Exejzro

Building the Subreddit Body

Look at the subreddit body from the example image once more. It consists of a background image, an icon and three texts. Since some elements overlap, you’ll use ConstraintLayout() for flexibility.

Qaltahdoj Sucg Gjeyoat
Pulnertoc Gaqy Fheliog

Adjusting the Elements’ Height and Shadowing

The elements’ positions are correct, but their height is wrong and there are no visible shadows at the edge.

Yajjivqah Hlaxuot
Qilhivbuh Rpepuoj

Building the Community Item

The community item is fairly simple; it only has an icon and a text. To build it, change Community() code to:

Hohsidehq Wyeweuh
Kogmigiqm Rqefiep

Adding a Community List

In this section, you’ll add the a list to show the communities available. Add the following code inside Communities():

Piznabikiox Xhamooh
Xofbeduteum Wcukoet

Finishing the Screen

The last part of the puzzle to build SubredditsScreen() is to combine everything you’ve built so far into a list that the user can scroll horizontally and vertically.

Batheddomg Lrmiun
Sotvifdudz Znbeiw

Key Points

  • If you see parts of a screen that repeat, use a component-based approach to extract them into separate composables.
  • Use Preview for iterating on the implementation of the components until you’ve built your whole screen.
  • Use emptyContent() to display empty content inside the composable.
  • Use zIndex() if multiple composables overlap and you want to change their order of display in the z-axis.
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now