简体   繁体   中英

How to put expandable ListView inside a ScrollView

I can't seem to scroll in my fragment. I have an expandable listview in the middle of editText and textViews and a textView and editText below the expandable listview. I can't scroll down to the bottom textView and editText. How do I format this so I can scroll all the way down without having to touch the listView?

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fillViewport="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
android:background="#FFFFFF"
android:orientation="vertical"
tools:context="edu.bradley.apawelczyk.trackapp.Add_Athlete_Fragment"
android:weightSum="1"
android:padding="20dp"
android:id="@+id/addAthleteLayout">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Add New Athlete"
    android:id="@+id/txtTitle"
    android:gravity="center"
    android:textColor="#000000"
    android:textSize="30dp"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtName"
    android:text="Name: "
    android:textColor="#000000"
    android:paddingBottom="10dp"/>
<EditText
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:id="@+id/editFirstName"
    android:hint="First Name"
    android:background="@drawable/edit_text_background"
    android:textColorHint="#BBBBBB"
    android:textColor="#000000"
    android:paddingLeft="10dp" />
<EditText
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:id="@+id/editLastName"
    android:hint="Last Name"
    android:background="@drawable/edit_text_background"
    android:textColorHint="#BBBBBB"
    android:textColor="#000000"
    android:paddingLeft="10dp"
    android:layout_marginTop="10dp"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtAge"
    android:text="Age: "
    android:textColor="#000000"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"/>
<EditText
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:id="@+id/editAge"
    android:hint=""
    android:background="@drawable/edit_text_background"
    android:textColorHint="#BBBBBB"
    android:textColor="#000000"
    android:paddingLeft="10dp" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtGrade"
    android:text="Grade: "
    android:textColor="#000000"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"/>
<EditText
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:id="@+id/editGrade"
    android:hint=""
    android:background="@drawable/edit_text_background"
    android:textColorHint="#BBBBBB"
    android:textColor="#000000"
    android:paddingLeft="10dp" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtEvent"
    android:text="Event: "
    android:textColor="#000000"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"/>
<ExpandableListView
    android:layout_width="400dp"
    android:layout_height="match_parent"
    android:id="@+id/eventsList"
    android:choiceMode="singleChoice"
    android:divider="#000000"
    android:dividerHeight="2dp"
    android:focusable="false">
</ExpandableListView>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtTier"
    android:text="Tier: "
    android:textColor="#000000"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"/>
<EditText
    android:layout_width="300dp"
    android:layout_height="40dp"
    android:id="@+id/editTier"
    android:hint=""
    android:background="@drawable/edit_text_background"
    android:textColorHint="#BBBBBB"
    android:textColor="#000000"
    android:paddingLeft="10dp" />

The layout you are trying to create would not work this way, ListView is not meant to be in ScrollView because the touch events will get consumed. For a ListView with scrollable headers you have to add those with addHeaderView() method (similar for footers). However, this cannot be done just with XML.

Your main XML should only contain the ExpandableListView , then I would suggest to create one XML with LinearLayout containing all the views you want to have above the ListView and another XML with the views that will be bellow. In your code just inflate those XMLs and call addHeaderView() and addFooterView() with them. Also if you use onItemClickListener note that header view will shift the index of views.

Expandable listview/listview do not recieve gestures because the scrollview handles them. Try changing your layout.

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