【问题标题】:Android: Can't get scroll a scrollviewAndroid:无法滚动滚动视图
【发布时间】:2016-03-14 16:01:17
【问题描述】:

我在使用 shinobi 图表方面很新。目前我正在尝试设计一个包含图表的布局。布局包含几个其他元素,所以我添加了一个滚动视图来正确管理所有内容......但滚动似乎不起作用......我的布局文件是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/box_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/box_title_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/box_title_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Titolo" />

        <ImageButton
            android:id="@+id/box_title_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/dettaglio" />

    </LinearLayout>
    <ScrollView
        android:id="@+id/fragment_detaill_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >

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

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

                <fragment
                    android:id="@+id/chart_fragment"
                    android:name="com.shinobicontrols.charts.ChartFragment"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

            </LinearLayout>

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

                <ListView
                    android:id="@+id/lvImageList"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </ListView>

            </LinearLayout>

        </LinearLayout>
    </ScrollView>
</LinearLayout>

效果在图表之前都是可见的,图表本身是可见的,但是图表下的listview没有。我试图向下滚动,但我无法让它工作。目前我正在使用 Nexus 7 进行开发。有人可以帮助我吗?

编辑:问题在于 ScrollView 不滚动!没有 ListView。如果我删除 ListView 和其他东西 ScrollView 仍然没有滚动!

【问题讨论】:

标签: android android-scrollview


【解决方案1】:

您不应该将 ListView 放在 ScrollView 中,因为 ListView 类实现了自己的滚动,并且它只是不接收手势,因为它们都由父 ScrollView 处理。 但我找到了一个适合我的解决方案,并且可以毫无问题地滚动 ListView。

ListView listView = (ListView)findViewById(R.id.lvImageList); 
listView .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;
        }

        v.onTouchEvent(event);
        return true;
}
});

父视图(即 ScrollView)上的 TouchEvent 将禁用并接收子视图(即 ListView)的手势。

【讨论】:

  • 是的,我知道,但我的问题是父 ScrollView 不滚动!我希望它确实如此,因为底部列表视图在屏幕之外......但没有滚动!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多