Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Linearlayout scrollable without using Scrollview

I have a Linearlayout and I want to make it scrollable without using ScrollView. Is it possible. Any suggestions will be appreciated. Here's the detail: If I wrap the LinearLayout using ScrollView, it is ok but when I used a ListView inside LinearLayout(because it is my clients requirement), it said do not use ListView inside ScrollView. I have to show 50 product list using ListView and I have to put this ListView inside LinearLayout and at the same time whole layout will be scrollable. Is it possible. Here is the skeleton:

<LinearLayout>
  <RelativeLayout>
    <LinearLayout> 
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <ListView>
    </LinearLayout> 
  </RelativeLayout>
</LinearLayout>

Important: See the ListView where I want to add 50 list item. So how can I make this total LinearLayout scrollable.

like image 520
androidcodehunter Avatar asked Jul 30 '26 18:07

androidcodehunter


1 Answers

Actually after doing some research, I come up with a solution for this problem:

At first I want to explain the problem in a very simple way.

  1. LinearLayout will be scrollable. To do this we can use ScrollView but sometimes we need to use ListView inside LinearLayout.
  2. We know that inside ScrollView we cannot use another scrollview like ListView

How to solve that?

ListView is scrollable inherently so we can add header and footer in the ListView. As a conclusion:

  1. Create Layout header.xml and footer.xml and list.xml
  2. Find the ListView reference from list.xml in the main activity and dynamically add header and footer in the ListView reference.
like image 112
androidcodehunter Avatar answered Aug 01 '26 06:08

androidcodehunter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!