使用协调器布局在ExpandableListView中滚动

问题描述 投票:0回答:1

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

我需要使用NestedScrollView,因为layout_navigation_view在所有地方都是通用的。

看看吧

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

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

activity main.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 ...
    }
 }

activity navigation view.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个回答
0
投票

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

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

添加SwipeRefreshLayout小部件要将刷卡小部件添加到现有应用程序,请添加SwipeRefreshLayout作为单个ListView或GridView的父级

解:

首先在SwipeRefreshLayoutNestedScrollView放在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>

并删除SwipeRefreshLayout中的activity_main.xml

© www.soinside.com 2019 - 2024. All rights reserved.