在NestedScrollView内设置自定义列表视图 [英] Set Custom List view inside NestedScrollView

查看:81
本文介绍了在NestedScrollView内设置自定义列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要移至Coordinator Layout和Nested ScrollView,我知道要使其正常工作,我需要使用recycle r视图,但事实是我真的想使旧的List View成为可能,有什么办法可以实现这一目标

I am moving to Coordinator Layout and Nested ScrollView and i know to make it work i need to use recycle r view but the thing is i really want to make it possible with old List View is there any way i can achieve that

这是我在做什么

<?xml version="1.0" encoding="utf-8"?>

<!-- NOT SET HERE:  android:fitsSystemWindows="true" -->
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_collapseMode="pin"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:layout_gravity="fill_vertical"
    app:behavior_overlapTop="32dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/ll_main_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff"
            android:divider="@android:color/transparent"
            android:dividerHeight="3dp"
            android:fadingEdge="horizontal"
            android:focusable="false"
            android:gravity="center"
            android:listSelector="#00000000" />
    </LinearLayout>

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

我也用过

android:fillViewport="true"

但这会扩展我的列表视图以匹配父级,但是现在没有滚动

but this expands my list view to match the parent but there is no scrolling now

请帮助我 我真的需要使用自定义列表"视图

Please help me i really need to use Custom List view

我们将非常感谢您的帮助.

Help will be really appreciated.

先感谢

推荐答案

如果确实需要使用ListView,则可以在自定义ListView上实现NestedScrollingChild.

If you really need to use a ListView, you can implement NestedScrollingChild on your Custom ListView.

以下应能工作:

public class NestedScrollingListView extends ListView implements NestedScrollingChild {

private final NestedScrollingChildHelper mScrollingChildHelper;

public NestedScrollingListView(Context context) {
   super(context);
   mScrollingChildHelper = new NestedScrollingChildHelper(this);
   setNestedScrollingEnabled(true);
}

public NestedScrollingListView(Context context, AttributeSet attrs) {
   super(context, attrs);
   mScrollingChildHelper = new NestedScrollingChildHelper(this);
   setNestedScrollingEnabled(true);
}

@Override
public void setNestedScrollingEnabled(boolean enabled) {
   mScrollingChildHelper.setNestedScrollingEnabled(enabled);
}

@Override
public boolean isNestedScrollingEnabled() {
   return mScrollingChildHelper.isNestedScrollingEnabled();
}

@Override
public boolean startNestedScroll(int axes) {
   return mScrollingChildHelper.startNestedScroll(axes);
}

@Override
public void stopNestedScroll() {
    mScrollingChildHelper.stopNestedScroll();
}

@Override
public boolean hasNestedScrollingParent() {
    return mScrollingChildHelper.hasNestedScrollingParent();
}

@Override
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed,
                                int dyUnconsumed, int[] offsetInWindow) {
    return mScrollingChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed,
        dxUnconsumed, dyUnconsumed, offsetInWindow);
}

@Override
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
    return mScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
}

@Override
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
    return mScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
}

@Override
public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
    return mScrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY);
}
}

这篇关于在NestedScrollView内设置自定义列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆