Today we’ll show you how to create a list view inside a scrollview in android. It’s very easy as you will see in the example below.
With the source code provided you can create a custom ListView, which is non Scrollable as you can see:
You can directly download the code of follow the steps of our tutorial.
public class NonScrollListView extends ListView { public NonScrollListView(Context context) { super(context); } public NonScrollListView(Context context, AttributeSet attrs) { super(context, attrs); } public NonScrollListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightMeasureSpec_custom = View.MeasureSpec.makeMeasureSpec( Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom); ViewGroup.LayoutParams params = getLayoutParams(); params.height = getMeasuredHeight(); } }
In Your Layout File
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fadingEdgeLength="0dp" android:fillViewport="true" android:overScrollMode="never" android:scrollbars="none" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <!-- com.Example Changed with your Package name --> <com.thedeveloperworldisyours.view.NonScrollListView android:id="@+id/lv_nonscroll_list" android:layout_width="match_parent" android:layout_height="wrap_content" > </com.thedeveloperworldisyours.view.NonScrollListView> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/lv_nonscroll_list" > <!-- Your another layout in scroll view --> </RelativeLayout> </RelativeLayout> </ScrollView>
In Java File
Create a object of your customListview instead of ListView like :
NonScrollListView non_scroll_list = (NonScrollListView) findViewById(R.id.lv_nonscroll_list);
Good job.!!
This is exactly what I was looking for. Thanks for sharing!
thank you
Great job bro!!!1
aaa this is great, thank you 😉
i wish the best for you it was exactly what i want
Thank you very much, you have saved my day!!!
Thank you so much! This is exactly what i was looking for! 🙂
Thank you very much I have been trying to figure this out for days now, never thought to make a custom class then call from it as a listview! :))))
This is a really great answer
thank you
It’s perfect. good job
Thank you so much bro… perfect code