【问题标题】:Android HorizontalScrolling laggyAndroid Horizo​​ntalScrolling 滞后
【发布时间】:2012-04-01 09:02:25
【问题描述】:

我有一个带有 LinearLayout 的 HorzontalScrollView。在运行时,我可以向 LinearLayout 添加更多 LinearLayout。

现在我遇到的问题是 Scrollview 只滚动一点点,并且用一根手指滑动并不平滑!

有人有解决这个问题的办法吗?

【问题讨论】:

    标签: android scroll horizontalscrollview


    【解决方案1】:

    Horizo​​ntalScrollView 不使用管理列表内存的适配器,因此它无法处理繁重的(图像、自定义视图等)列表。

    你可以使用这个Horizo​​ntal ListView http://www.dev-smart.com/archives/34,但是要确保你不要在getView里面写on list item click方法,它会让列表滚动变慢。除此之外,这是平滑水平列表视图的绝佳资源。

    您还可以探索 Android 视图分页器,使用兼容包的较低 Android 版本也支持该功能:http://developer.android.com/sdk/compatibility-library.html

    编辑 - 类似适配器中的东西,它会膨胀您想要的 XML(线性布局),然后用相关数据填充每个视图。

        @Override
                public View getView(final int position, View convertView, ViewGroup parent) {
    
                    if (convertView == null) {
                        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_friends_list_item, null);
                    }
    
                    ImageView status = (ImageView)convertView.findViewById(R.id.status);
                    ImageView image = (ImageView)convertView.findViewById(R.id.image);
                    ImageView imageBorder = (ImageView)convertView.findViewById(R.id.image_border);
                    TextView title = (TextView)convertView.findViewById(R.id.title);
    }
    

    【讨论】:

    • 你知道我是怎么做到的吗?如果列表视图中没有元素,则将整个宽度的不同线性布局元素添加到列表视图中?
    • @matchi1992 在 listview 适配器的 getview 中,填充线性布局元素 XML。查看更新的答案。
    【解决方案2】:

    问题出在我的父 Viewflow 上,因为它窃取了滑动事件! Horizo​​ntalListView 对我来说太麻烦了! (大小属性的问题)

    不过,谢谢您的回答! ;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多