android - listview android 在某些设备上滚动,而在其他设备上不滚动

标签 android listview landscape-portrait

ListView 在某些设备 Nexus_5x 上滚动,但在 Samsung Galaxy Tab 7 上不滚动

我尝试了互联网上的所有内容:

这行不通!

// save index and top position
int index = mList.getFirstVisiblePosition();
View v = mList.getChildAt(0);
int top = (v == null) ? 0 : (v.getTop() - mList.getPaddingTop());

// ...

// restore index and position
mList.setSelectionFromTop(index, top);

链接在这里

Maintain/Save/Restore scroll position when returning to a ListView

这也不起作用

ListView lv = (ListView)findViewById(R.id.myListView);  // your listview inside scrollview
lv.setOnTouchListener(new ListView.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(true);
                break;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }

            // Handle ListView touch events.
            v.onTouchEvent(event);
            return true;
        }
    });

链接在这里

ListView inside ScrollView is not scrolling on Android

我的listView xml是

 <ListView
        android:id="@+id/listview"
        style="@style/ListView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginEnd="5dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="8dp"

        android:visibility="visible"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonClear"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

横向不行,但纵向就可以了。

我不明白为什么它在某些设备上甚至纵向模式上都可以,但在其他设备上却不行?

最佳答案

首先,将可 ScrollView 嵌套在另一个 View 中并不总是一个好主意,特别是当它们朝同一方向滚动时,尽管在某些情况下没有太多替代方案。当我想在 ScrollView 中实现类似回收器 View 的东西时,我禁用回收器 View 的滚动行为并根据内容的大小扩展尺寸

http://www.it1me.com/it-answers?id=33330388&ttl=How+to+put+RecyclerView+inside+NestedScrollView%3F

这是一个指向其实现位置的链接。研究一下,你就会明白了。 祝你好运

关于android - listview android 在某些设备上滚动,而在其他设备上不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45285132/

相关文章:

android - 重写 getText() 后,EditText 中的光标消失了

android单选列表选择问题?

Android 在横向和纵向中重用布局

android - 在 Android 中设计 ListView

Android:根据滚动位置动态加载数据的 ListView

java - 单击 ListView 中的任何项目时应用程序崩溃

Android 如何在动态 ListView 中显示数组列表索引号

html - 在纵向和横向之间切换时如何获得响应式 CSS 以适应视口(viewport)?

objective-c - 如何正确切换到横向 View ?

android - 使用 kotlin 在 android 中与底部工作表进行数据绑定(bind)