【问题标题】:Horizontal ScrollVIew inside ListView not scrollling properlyListView 内的水平 ScrollVIew 不能正确滚动
【发布时间】:2015-01-23 06:15:52
【问题描述】:

我刚刚在 ListView 中实现了 Horizo​​ntalScrollView。但列表视图滚动不顺畅。 我想显示一个列表视图,并且一些列表项有一个 Horizo​​ntalScrollView。我的 Horizo​​ntalScroll 可以平滑滚动,但 Listview 不是。

以下是我的代码:

    <ListView 
        android:id="@+id/list_view"
        android:scrollbars="none"
        android:visibility="gone"
        android:divider="@color/LtGreen"
        android:dividerHeight="1dp"

        android:smoothScrollbar="true"
        android:scrollingCache="false"
        android:animationCache="false"
        android:cacheColorHint="@android:color/transparent"
        android:listSelector="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

我在适配器类中的 getView 方法的代码是 -

mHolder.mainLinearType1 = (LinearLayout) view.findViewById(R.id.main_linear);
mHolder.hsv1 = (HorizontalScrollView) view.findViewById(R.id.hsv);

适配器项的加载 Horizo​​ntalScrollView 的代码是 -

    ScrollHandler mHandel = new ScrollHandler(mHolder.mainLinearType1, position);
    mHandel.loadLazyView();

我的处理程序是 -

public static class ScrollHandler extends Handler{

    LinearLayout mLayout;
    int mPosition;

    public ScrollHandler(LinearLayout linear,int pos){
        mLayout = linear;
        mPosition = pos;
    }

    public void loadLazyView(){
        Runnable r = new Runnable() {
            @Override
            public void run() {
                mLayout.removeAllViews();
                for (int i = 0; i <mList.get(mPosition).getEventList().size(); i++) {
                    View additionView = mLayoutInflater.inflate(R.layout.activity_type1_subitem_view, null,false);
                    FrameLayout innerLinnerLayout=(FrameLayout)additionView.findViewById(R.id.frame_view);
                    mLayout.addView(innerLinnerLayout);
                }
            }
        };
        r.run();
    }
}

我怎样才能使列表视图流畅。

提前致谢。

【问题讨论】:

  • 你不能在android中进行嵌套滚动,而是查看页眉或页脚

标签: android listview android-listview horizontalscrollview


【解决方案1】:

检查一下:

http://developer.android.com/training/improving-layouts/smooth-scrolling.html

我认为这就是你所需要的。使用 ASyncTask 应该会很顺利。

【讨论】:

    【解决方案2】:

    为什么当 ScrollHandler 不做任何特定于处理程序的工作时,它会扩展 Handler?逻辑可以用简单的方法实现,比如

    loadLazyView (LinearLayout linear,int pos){...}
    

    我认为列表很慢,因为它具有复杂的层次结构。以下链接列出了 6 种使滚动更流畅的一般方法。如果您已经看过,请原谅。

    http://leftshift.io/6-ways-to-make-your-lists-scroll-faster-than-the-wind

    总结是

    1. 减少适配器的 getView 中使用的条件数。
    2. 检查并减少您在日志中收到的垃圾收集警告的数量
    3. 如果您在滚动时加载图像,请删除它们
    4. 将 scrollingCache 和 animateCache 设置为 false(稍后会详细介绍)
    5. 简化列表视图行布局的层次结构
    6. 使用视图支架模式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多