【问题标题】:Android: ListView like RetailMeNot appAndroid:ListView 类似 RetailMeNot 应用
【发布时间】:2015-05-28 18:42:51
【问题描述】:

刚刚发现这个应用程序RetailMeNot Coupons。使用的列表视图是自定义的,看起来很酷。最初,列表显示子项的较小图像。当用户向上滚动时,子项会完全展开以显示更大的图像。

出于好奇,我计划在测试应用中构建一个类似的列表视图。 我确定这是一个自定义列表视图,有人看过类似列表视图的库或实现吗?

【问题讨论】:

  • 可能是混合应用。
  • 它不是 Hybrid 应用,它是 anroid 的原生应用 @Apurva
  • @Faheem 你实现了吗?
  • @Faheem Kalsekar 你做过这个列表视图吗?
  • 能达到这个效果吗?

标签: android listview custom-lists


【解决方案1】:

我尝试过直接使用 listviewscroll。

并不完美,但只是一个开始

public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    getListView().setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            for (int j=0; j<visibleItemCount; j++) {
                if(absListView.getChildAt(j).getClass() == FrameLayout.class) {
                    FrameLayout item = (FrameLayout) absListView.getChildAt(j);
                    String result = "";
                    if (item != null) {
                        RelativeLayout relative1 = (RelativeLayout) item.getChildAt(0);
                        ImageView promoImage = (ImageView) relative1.getChildAt(0);
                        View promoOverlay = (View) relative1.getChildAt(1);
                        RelativeLayout relative2 = (RelativeLayout) relative1.getChildAt(2);
                        ImageView brandImage = (ImageView) relative2.getChildAt(0);
                        TextView promoText = (TextView) relative2.getChildAt(1);
                        item.setLayoutParams(new AbsListView.LayoutParams(item.getWidth(), (int) minHeight));
                        if (item.getTop() < maxHeight) {
                            if (item.getTop() >= 0) {
                                float topPercent = item.getTop() / maxHeight;
                                float newHeight = minHeight + ((maxHeight - minHeight) * (1 - topPercent));
                                if (newHeight <= maxHeight) {
                                    item.setLayoutParams(new AbsListView.LayoutParams(item.getWidth(), (int) newHeight));
                                    promoOverlay.setAlpha(topPercent / 2);
                                } else {
                                    item.setLayoutParams(new AbsListView.LayoutParams(item.getWidth(), (int) maxHeight));
                                    if (item.getTop() > 0) {
                                        promoOverlay.setAlpha(0.5f);
                                    } else {
                                        promoOverlay.setAlpha(0f);
                                    }
                                }
                            } else {
                                float topPercent = (-item.getTop()) / maxHeight;
                                float newHeight = maxHeight - ((maxHeight - minHeight) * (topPercent));
                                if (newHeight >= minHeight) {
                                    item.setLayoutParams(new AbsListView.LayoutParams(item.getWidth(), (int) newHeight));
                                    promoOverlay.setAlpha(topPercent / 2);
                                } else {
                                    item.setLayoutParams(new AbsListView.LayoutParams(item.getWidth(), (int) minHeight));
                                }
                                promoOverlay.setAlpha(0);
                            }
                        } else {
                            if (item.getTop() > 0) {
                                item.setLayoutParams(new AbsListView.LayoutParams(item.getWidth(), (int) minHeight));
                                promoOverlay.setAlpha(0.5f);
                            }
                        }

                    }
                }
            }
        }
    });

}

【讨论】:

    【解决方案2】:

    看看这个库

    https://github.com/ksoichiro/Android-ObservableScrollView

    也许这个库的一些定制可以帮助你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      • 2011-10-20
      • 2014-03-01
      • 1970-01-01
      相关资源
      最近更新 更多