android - How to make Linearlayout scrollable with two listviews scrollable which wrap their content -


i know has been asked many times still have yet find solution like. can please suggest elegant way i'm trying do:

i have 2 listviews have in linearlayout (vertical). want listviews wrap content when comes height never need scroll internally. instead, scroll down on page in order see overflows.

thanks in advance help! if suggest re-doing architecture i'm open well. thing ask solution clean , simple possible. hackish workarounds not preferred. :)

as far know, trying make listview height content requires.

you can create custom listview extends listview , override onmeasure method this:

public class unscrollablelistview extends listview {      public unscrollablelistview(context context) {         super(context);     }      public unscrollablelistview(context context, attributeset attrs) {         super(context, attrs);     }      public unscrollablelistview(context context, attributeset attrs,             int defstyle) {         super(context, attrs, defstyle);     }      @override     protected void onmeasure(int widthmeasurespec, int heightmeasurespec) {         int maxheightspec = measurespec.makemeasurespec(                  integer.max_value >> 2, measurespec.at_most);          super.onmeasure(widthmeasurespec, maxheightspec);      }  } 

this make listview wrap content.

as need scroll down, try add scrollview in layout wrap linearlayout. finally, layout like:

<?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" >      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical" >          <com.example.unscrollablelistview             android:id="@+id/listview1"             android:layout_width="match_parent"             android:layout_height="wrap_content" />          <com.example.unscrollablelistview             android:id="@+id/listview2"             android:layout_width="match_parent"             android:layout_height="wrap_content" />     </linearlayout>  </scrollview> 

is want?

but have these codes make listview perform vertical linearlayout lot of similar children. not take advantage of recycling views improve layout performance because no view going recycled.

you can have on article: performance tips android’s listview


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -