0

I am dynamically adding children in LinearLayout horizontally. I am adding child on button click. But after adding some children, say 4, others children go out of screen as these are being added horizontally. How can I check that child is going beyond screen in LinearLayout, and I need to create new layout? Or what can I do with the LinearLayout so that when it goes out of screen, it wraps itself?

Any help? Thanks in advance.

Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46

1 Answers1

0

Just put your LinearLayout inside HorizontalScrollView, it will do all the necessary work for you:

<?xml version="1.0" encoding="utf-8"?>

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent">

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    </LinearLayout>
</HorizontalScrollView>

EDIT if you want your views to be wrapped inside the parent view, please take a look here Line-breaking widget layout for Android

Community
  • 1
  • 1
nikis
  • 11,166
  • 2
  • 35
  • 45
  • It has created scrolling horizontally but I want that when space is filled horizontally, add child to the next row and so on. Can this be achieved? Thanks – Mustansar Saeed Mar 06 '14 at 18:11