简体   繁体   中英

Android Linear Layout with four Listview is not scrolling inside Scrollview

I am using LinearLayout with vertical orientation and inside that layout I am having four ListView . This layout I have placed inside ScrollView .

My problem is ScrollView is not scrolling. So I am not able to see my all list views.

What i am doing is:

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView1"
android:layout_width="wrap_content"
android:layout_height="600dp"
android:fillViewport="true" >




             <LinearLayout
                 android:id="@+id/frag_capt2"
                 android:layout_width="800dp"
                 android:layout_height="match_parent"
                 android:layout_marginLeft="100dp"
                 android:layout_marginTop="20dp"
                 android:orientation="vertical" >

                 <TextView
                     android:id="@+id/linearlayoutteamtv1"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:text="Medium Text"
                     android:textAppearance="?android:attr/textAppearanceMedium"
                     android:textColor="#000000" />


                 <ListView
                     android:id="@+id/ListView01team"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="10dp"
                     android:background="@drawable/pm_cool_listproject_background" >

                 </ListView>



                 <TextView
                     android:id="@+id/linearlayoutteamtv2"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="10dp"
                     android:text="Medium Text"
                     android:textAppearance="?android:attr/textAppearanceMedium"
                     android:textColor="#000000" />



                 <ListView
                     android:id="@+id/ListView02team"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="10dp"
                     android:background="@drawable/pm_cool_listproject_background" >

                 </ListView>

                  <TextView
                     android:id="@+id/linearlayoutteamtv3"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="10dp"
                     android:text="Medium Text"
                     android:textAppearance="?android:attr/textAppearanceMedium"
                     android:textColor="#000000" />



                 <ListView
                     android:id="@+id/ListView03team"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="10dp"
                     android:background="@drawable/pm_cool_listproject_background" >

                 </ListView>



                  <TextView
                     android:id="@+id/linearlayoutteamtv4"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="10dp"
                     android:text="Medium Text"
                     android:textAppearance="?android:attr/textAppearanceMedium"
                     android:textColor="#000000" />



                 <ListView
                     android:id="@+id/ListView04team"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="10dp"
                     android:background="@drawable/pm_cool_listproject_background" >

                 </ListView>


             </LinearLayout>
</ScrollView>

I do not understand what my code is missing.

A listview should NOT be inside any scrolling element or vice versa. please have a look at what google developers have to say about it.Please check this Video

you can set all four listview height..like...

 <ListView
            android:id="@+id/lst_tree_hazard"
            android:layout_width="fill_parent"
            android:layout_height="80dp"       ///set the height based on your listview content
            android:scrollbars="none" >
 </ListView>

You dont need to have a ScrollView for a ListView . I think you can easily use RelativeLayout and specify the order of the ListViews

Generally, you cannot put scrollable things inside other scrollable things, where they scroll in the same direction, and have the results be reliable. Occasionally this works (eg, WebViews in a ViewPager ), but that is the exception, not the norm.

Either:

Move the ListView out of the ScrollView , or

Move all the rest of the contents of the ScrollView into the ListView, whether using things like addHeaderView() or my MergeAdapter

You just can't do that that way! However, there is solution to you problem, multiple types of list items within single list . Differences between single type list items:

  • define list item types, ie. (header, list1_type, list2_type,... main_header?, main_footer?) , override getViewTypeCount()
  • override getItemViewType(...) ,
    • is index_of_header -> 0
    • is index_of_type1 -> 1
    • is index_of_type2 -> 2
  • more complex getView(...)
    • get item view type, hint: use already made function
    • dispatch view creation based on type, don't forget, that convertView argument is view for current item type, you should reuse it , if not null!

You may create your own abstract class for merging adapter, as mentioned in another answer. It's just basically what I explained above. Sometimes you just can't use merge adapter, ie. recursive structures, but there is good idea to consider using ExpandableListView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM