When I put ListView in ScrollView, it scrolls to the bottom when updating ListView.

Asked 2 years ago, Updated 2 years ago, 38 views

Use ViewPager for Activity with ScrollView as Root and
We are trying to create a top cover image + horizontal scrolling page like the one below.

The Fragment on the page is created in ListView and the content is displayed in a list format, but when I call notifyDataSetChange() in ListView, the entire screen is scrolled to the bottom.
Also, when you call the ViewPager setCurrentItem(), it scrolls to the bottom as well.

Please let me know if anyone knows any effective means of this event.

 ---------------------
 | toolbar|
 -----------------
 | Cover|
 |               |
 |               |
 -----------------
 | tab|
 -----------------
 | Fragment*4|
 |               |
 |               |
 -----------------

■ Activity layout

<?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="wrap_content">

    <View
        android: id="@+id/header_content"
        android:layout_width="match_parent"
        android:layout_height="100dp"/>

    <ViewPager
        android:layout_width="match_parent"
        android: layout_height="640dp"/>
</ScrollView>

■Fragment layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="640dp">

<ListView
    android:id="@+id/list_view"
    android:layout_width="match_parent"
    android:layout_height="640dp"
    android:clipToPadding="false"
    android: divider="@null"
    android: dividerHeight="0dp"
    android:fadingEdge="none"
    android:fastScrollEnabled="true"
    android:listSelector="@android:color/transparent"
    android:scrollbars="none"/>

<View
    android:id="@+id/no_match_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</FrameLayout>

android

2022-09-30 14:30

1 Answers

The mystery is that the contents of ScrollView are not in LinerLayout.
I think it will be solved if I put it in LinerLayout...

Also, is it because there is no view to display tab and Fragment?


2022-09-30 14:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.