【问题标题】:Expandable listview not scrolling inside relatvive layout可扩展的列表视图不在相对布局内滚动
【发布时间】:2018-11-01 05:47:07
【问题描述】:

在我的页面中,我在下面的顶部有一个 searchView,它有一个 viewPager 来显示图像和一个 expandablelistview。当列表视图展开时,我需要将整个视图向上滚动到顶部,我该如何实现这一点,请帮助

<?xml version="1.0" encoding="utf-8"?>
        <Scrollview 
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="?actionBarSize">

             <SearchView
                    android:id="@+id/search_bar"
                    android:layout_width="401dp"
                    android:layout_height="45dp"
                    android:layout_alignParentTop="true"
                    android:background="@drawable/bg_white_rounded"
                    android:queryBackground="@android:color/transparent"
                    android:queryHint="Search" />


                <android.support.v4.view.ViewPager
                    android:id="@+id/viewPager"
                    android:layout_width="match_parent"
                    android:layout_height="150dp"
                    android:layout_below="@+id/Constraint1"
                    android:layout_marginBottom="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />


            <ExpandableListView
                android:id="@+id/expandible_listview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:divider="@null"
                android:groupIndicator="@null"
                android:isScrollContainer="false"
                android:layout_below="@id/Constraint2"
                android:childDivider="#00000000"
                />
        </RelativeLayout>

    </Scrollview>

【问题讨论】:

  • 要么删除父 ScrollView,要么将其替换为 NestedScrollView 并禁用 ListView 上的嵌套滚动。
  • 对不起,它不适合我
  • NestedScrollViewandroid:fillViewPort="true"一起使用,并将相对布局高度从match_parent更改为wrap_content

标签: android expandablelistview android-scrollview android-relativelayout


【解决方案1】:

你可以在你的代码中使用它

mainScrollView.fullScroll(ScrollView.FOCUS_UP);

【讨论】:

  • 一般来说,如果答案包含对代码的用途的解释,以及为什么在不介绍其他人的情况下解决问题的原因,答案会更有帮助。
猜你喜欢
  • 1970-01-01
  • 2012-02-27
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 2016-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多