android development
horizontal listview
android ui
listview customization
android programming

Horizontal ListView in Android?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

If you want a horizontal scrolling list in Android, the modern answer is usually not ListView at all. The standard solution is RecyclerView with a horizontal LinearLayoutManager, because it handles recycling, scrolling, and item decoration far better than the older ListView workarounds.

Use RecyclerView with a Horizontal Layout Manager

Start by placing a RecyclerView in your layout.

xml
1<?xml version="1.0" encoding="utf-8"?>
2<androidx.recyclerview.widget.RecyclerView
3    xmlns:android="http://schemas.android.com/apk/res/android"
4    android:id="@+id/photoRecyclerView"
5    android:layout_width="match_parent"
6    android:layout_height="120dp" />

Then configure it in code with a horizontal LinearLayoutManager.

kotlin
1import android.os.Bundle
2import androidx.appcompat.app.AppCompatActivity
3import androidx.recyclerview.widget.LinearLayoutManager
4import androidx.recyclerview.widget.RecyclerView
5
6class MainActivity : AppCompatActivity() {
7    override fun onCreate(savedInstanceState: Bundle?) {
8        super.onCreate(savedInstanceState)
9        setContentView(R.layout.activity_main)
10
11        val recyclerView = findViewById<RecyclerView>(R.id.photoRecyclerView)
12        recyclerView.layoutManager = LinearLayoutManager(
13            this,
14            RecyclerView.HORIZONTAL,
15            false
16        )
17        recyclerView.adapter = LabelAdapter(listOf("One", "Two", "Three", "Four"))
18    }
19}

That single layout-manager setting is what turns the list sideways.

A Minimal Adapter Looks Familiar

The adapter pattern is the same as any other RecyclerView.

kotlin
1import android.view.LayoutInflater
2import android.view.View
3import android.view.ViewGroup
4import android.widget.TextView
5import androidx.recyclerview.widget.RecyclerView
6
7class LabelAdapter(private val items: List<String>) :
8    RecyclerView.Adapter<LabelAdapter.LabelViewHolder>() {
9
10    class LabelViewHolder(view: View) : RecyclerView.ViewHolder(view) {
11        val textView: TextView = view.findViewById(R.id.labelText)
12    }
13
14    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LabelViewHolder {
15        val view = LayoutInflater.from(parent.context)
16            .inflate(R.layout.list_item_label, parent, false)
17        return LabelViewHolder(view)
18    }
19
20    override fun onBindViewHolder(holder: LabelViewHolder, position: Int) {
21        holder.textView.text = items[position]
22    }
23
24    override fun getItemCount(): Int = items.size
25}

What changes is not the adapter itself but the scroll direction and the item layout assumptions.

Why Not HorizontalScrollView Plus Manual Children

For a handful of static views, a HorizontalScrollView may be acceptable. But once the content is data-driven or can grow, RecyclerView is the better long-term choice because it recycles views, supports snapping, and integrates with the rest of the modern Android UI stack.

Older custom "HorizontalListView" widgets mostly existed to work around limitations that RecyclerView already solved.

Improve the UX with Snapping and Spacing

Horizontal lists often benefit from SnapHelper so scrolling lands cleanly on card boundaries.

kotlin
import androidx.recyclerview.widget.LinearSnapHelper

LinearSnapHelper().attachToRecyclerView(recyclerView)

Item spacing is usually cleaner when handled by ItemDecoration rather than by hard-coding margins into every layout.

These small details matter because horizontal lists are often used for carousels, image strips, and recommendation shelves where polish is very visible.

Watch Nested Scrolling Behavior

A horizontal list often lives inside a vertically scrolling screen. That is fine, but gesture interaction should be tested carefully. Poorly sized items or overly greedy parents can make sideways scrolling feel broken even when the code is technically correct.

This is a UX problem as much as a widget problem.

Accessibility also deserves explicit attention in horizontal collections. Focus order, content descriptions, and predictable sideways navigation matter more in carousels than many teams expect, because the layout is less conventional than a simple vertical list.

Testing on small and large screens matters too, because horizontal card widths that feel fine on one device can become cramped or wasteful on another. Item sizing should be treated as part of the component design, not as an afterthought.

Common Pitfalls

Reaching for old custom horizontal ListView libraries instead of using RecyclerView adds complexity for no real benefit in modern Android code.

Designing item layouts as if the list were vertical often produces awkward widths and poor touch targets.

Ignoring nested-scroll behavior can make the horizontal list feel unreliable inside a vertical parent layout.

Summary

  • For a horizontal list in Android, use RecyclerView, not legacy ListView workarounds.
  • Set a horizontal LinearLayoutManager to change scroll direction.
  • Use the same adapter pattern you would use for any RecyclerView.
  • Add snapping and spacing deliberately for a better carousel-like experience.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.