在NestedScrollView中使用ListView不能正常工作

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

在Android中,图像视图应在启动滚动之前消失,但反向运行。如果我在Imageview消失之前向上和向下滚动,当我在屏幕上按住手指时,滚动视图开始向下滚动,然后Imageview开始关闭。这是我的代码。

<android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
       <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/user_menu_bg"
            android:orientation="vertical">

            <ListView
                android:id="@+id/menu_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@drawable/menu_list_divider"
                android:listSelector="@android:color/transparent"
                android:nestedScrollingEnabled="true" />
        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>
android listview scrollview android-nestedscrollview
1个回答
0
投票

最好使用NonScrollableListView而不是listview。或者使用RecyclerView

尝试

public class NonScrollListView extends ListView {

    public NonScrollListView(Context context) {
        super(context);
    }
    public NonScrollListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
                    Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = getMeasuredHeight();    
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.