【问题标题】:Scrolling in ExpandableListView with coordinator layout使用协调器布局在 ExpandableListView 中滚动
【发布时间】:2018-09-07 10:45:56
【问题描述】:

我的问题是使用协调器布局设计在 ExpandableListView 中滚动。 工具栏工作正常,当它触摸时,它会隐藏,但 ExpandableListView 不滚动

我需要使用 NestedScrollView,因为 layout_navigation_view 无处不在。

看看

picture http://info-sys.persiangig.com/noScroll.gif

我使用 Java 的主要代码和我使用 XML 的设计代码是:

ActivityMain.java

public class ActivityMain   extends ActivityNavigationView {

           ArrayList<StructNote> group ; //StructNote public String id,title,icon; // StructNote = Filde Parametr
           ArrayList<ArrayList<StructNote>> child ;

           ActivityAdapter mAdapter; // class extends BaseExpandableListAdapter 

           ExpandableListView exListView ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // ---> content_frame =>  layout_navigation_view.xml
        FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content_frame); 
        getLayoutInflater().inflate(R.layout.activity_main, contentFrameLayout);

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.getMenu().getItem(1).setChecked(true);

        exListView = (ExpandableListView) findViewById(R.id.exListView);

        //... Fill Group Child Adapter List
        //...Other CODE ...
    }
 }

ActivityNavigationView.java

public class ActivityNavigationView extends AppCompatActivity {

    DrawerLayout drawerLayout;
    ActionBarDrawerToggle actionBarDrawerToggle;
    Toolbar toolbar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_navigation_view);
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        //...Other CODE ... Click menu and Open close NavigationView, Toolbar
    }
 }

layout_navigation_view.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/background_light"
            android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/main.appbar"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/main.collapsing"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp">

            <ImageView
                android:id="@+id/main.backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                android:src="@drawable/bg_tool_bar"
                app:layout_collapseMode="parallax"/>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:popupTheme="@style/AppTheme.PopupOverlay"
                    app:layout_collapseMode="pin">
                </android.support.v7.widget.Toolbar>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>


        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        </android.support.v4.widget.NestedScrollView>


            <android.support.design.widget.FloatingActionButton
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_margin="@dimen/activity_horizontal_margin"
                android:src="@android:drawable/ic_dialog_info"
                app:layout_anchor="@id/main.appbar"
                app:layout_anchorGravity="bottom|right|end" />

        </android.support.design.widget.CoordinatorLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_activity_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeToRefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

            <ExpandableListView
                android:id="@+id/exListView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:transcriptMode="disabled"
                android:divider="@null"
                android:dividerHeight="0dp"
                android:minHeight="130dp">
            </ExpandableListView>

    </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

编辑:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical">


            <ExpandableListView
                android:id="@+id/exListView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:transcriptMode="disabled"
                android:divider="@null"
                android:dividerHeight="0dp"
                android:minHeight="130dp">
            </ExpandableListView>

</LinearLayout>

【问题讨论】:

    标签: android scroll expandablelistview android-toolbar android-coordinatorlayout


    【解决方案1】:

    工具栏工作正常,当它被触摸时,它会被隐藏,但ExpandableListView 不滚动

    是的,这是因为 SwipeRefreshLayout 和使用 SwipeRefreshLayout inside of NestedScrollView

    添加 SwipeRefreshLayout 小部件 将滑动刷新小部件添加到 一个现有的应用程序,添加SwipeRefreshLayout 作为单个应用程序的父级 ListView 或 GridView

    解决方案:

    首先将SwipeRefreshLayout 放在NestedScrollView 之外的layout_navigation_view.xml 中:

    <android.support.v4.widget.SwipeRefreshLayout 
        android:id="@+id/swipeToRefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">
            ...
        </android.support.v4.widget.NestedScrollView>
    
    </android.support.v4.widget.SwipeRefreshLayout>
    

    并删除activity_main.xml 中的SwipeRefreshLayout

    【讨论】:

    • 是的,我知道,这适用于 ListvVew、GrideView 和 RecyclerView 它不适用于 ExpandableListView,我需要滚动 **ExpandableListView **
    • public class ExpandableListView extends ListView 它从 ListView 扩展 并且由于您在 NestedScrollView 内添加了 SwipeRefreshLayout 这会导致问题。而SwipeRefreshLayout 不是滚动所需要的。
    • “SwipeRefreshLayout”并不重要,它不会引起问题
    • 哦,我错过了这个。试试这个:stackoverflow.com/a/37605908/4409113 这是因为 (ExpandableListView & NestedScrollView) 两者都是可滚动的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多