【问题标题】:Scrollview doesn't scroll with 2 listviewScrollview 不使用 2 listview 滚动
【发布时间】:2016-06-23 18:06:23
【问题描述】:

我搜索了很多关于滚动视图的主题,但没有人可以解决我的问题:/ 如果有人可以帮助我:) 当我从服务器发出请求时,每个列表视图都会打印一些人 通常,当我向下滚动列表时,第二个列表会出现,但不会出现

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/selector_for_background_white"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/selector_for_background_white"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/layoutScrollResult"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@drawable/selector_for_background_white">

                    <LinearLayout
                        android:id="@+id/layout2"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:orientation="horizontal">

                        <com.whask.whask.utils.font.FontTextView
                            android:id="@+id/text_hot"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_gravity="center"
                            android:layout_marginLeft="10dp"
                            android:layout_marginStart="10dp"
                            android:background="@android:color/transparent"
                            android:text="5 HOT"
                            android:textSize="@dimen/abc_text_size_medium_material"
                            app:font="Neo-Sans-Std-Medium.otf"/>
                    </LinearLayout>


                    <ListView
                        android:id="@+id/result_whask_listview_view"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/layout2">
                    </ListView>

                    <LinearLayout
                        android:id="@+id/layout3"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:layout_below="@+id/result_whask_listview_view"
                        android:orientation="horizontal">

                        <com.whask.whask.utils.font.FontTextView
                            android:id="@+id/text_not"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:layout_gravity="center"
                            android:layout_marginLeft="10dp"
                            android:layout_marginStart="10dp"
                            android:background="@android:color/transparent"
                            android:text="2 NOT"
                            android:textSize="@dimen/abc_text_size_medium_material"
                            app:font="Neo-Sans-Std-Medium.otf"/>
                    </LinearLayout>

                    <ListView
                        android:id="@+id/result_whask_listview_view_no"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/layout3"
                        android:background="@color/my_whask_white_color">
                    </ListView>

                </RelativeLayout>

            </LinearLayout>

        </LinearLayout>

    </ScrollView>

</LinearLayout>

【问题讨论】:

  • 你不应该使用滚动视图和列表视图,因为列表视图有它自己的滚动。而不是使用列表视图在线性或框架布局中膨胀您的项目。通过这种方式,您可以轻松实现包装内容功能,因为列表视图无法正常使用包装内容
  • 你想在滚动视图中滚动列表视图吗? @Mavrick Rmx
  • 如果我不使用 ScrollView,我的 2 FontTextView 将不会滚动,而我的第二个 listview 停留在底部,我看不到这些元素,我需要我的 FontTextView 也滚动@VivekMishra
  • 我并不是说你不应该使用滚动视图。我是说不要在滚动视图中使用列表视图。
  • 是的,这就是我想要的,然后我在屏幕底部的 listView 可以替换第一个 listview @Rushabh042

标签: java android listview android-studio scrollview


【解决方案1】:

如果你想在 Scrollview 中滚动列表视图,那么就这样做吧。

 ListView result_whask_listview_view;
 result_whask_listview_view = (ListView)findViewById(R.id.result_whask_listview_view);

 result_whask_listview_view.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;
                    }
                });

这样你可以在滚动视图中滚动列表视图。

希望对你有帮助:)

【讨论】:

    【解决方案2】:

    Listview 有自己的滚动属性,所以不要在滚动视图中使用... 谢谢

    【讨论】:

      【解决方案3】:

      请勿ScrollView 中使用ListViewListView 本身具有滚动属性,您不必使用另一个 ScrollView 使其滚动。请改用LinearLayout

      【讨论】:

        猜你喜欢
        • 2013-10-01
        • 2013-09-19
        • 1970-01-01
        • 2015-07-29
        • 2016-09-03
        • 1970-01-01
        • 1970-01-01
        • 2011-09-06
        • 2015-05-22
        相关资源
        最近更新 更多