【问题标题】:Not working properly with using ListView in NestedScrollView在 NestedScrollView 中使用 ListView 无法正常工作
【发布时间】:2018-05-21 08:10:20
【问题描述】:

在 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】:

    最好使用 NonScrollableListView 而不是列表视图。或使用 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();    
        }
    }
    

    【讨论】:

    • @StrongStorm 很高兴为您提供帮助:)
    • 再次嗨 @Jyoti JK :) ,我无法获得 onMeasure 方法,你能帮帮我吗?
    猜你喜欢
    • 2018-02-19
    • 2015-10-28
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    相关资源
    最近更新 更多