【问题标题】:Coverflow recenters itself while scrolling, when OnItemSelected changes other views当 OnItemSelected 更改其他视图时,Coverflow 会在滚动时自行居中
【发布时间】:2012-08-25 11:47:40
【问题描述】:

尊敬的 Stackoverflow 社区,

我有一个非常奇怪的问题。首先,我构建了某种“选择器”活动,它只不过是左侧的 WheelView、中心的 Coverflow 和下方的另一个(较小的)coverflow。顺便提一句。 CoverFlow 是一个被某些逻辑覆盖的图库。

中心覆盖流使用 BaseAdapter。我创建了一组列表,每次我的coverflow 获取新内容时,我都会使用其中一个列表创建一个新的 BaseAdapter 实例。在我的情况下,当在下部 CoverFlow 中选择一个项目时,这是完成的。所以我实现了一个 OnItemSelectedListener,以检查何时发生。滚动此封面流会导致视图始终“notifyDataSetChanged”并在某些情况下更改适配器。现在这就像一个魅力。

由于我在这个选择器(中心覆盖流)中有很多对象,我决定继续使用 CursorAdapter 来提高性能。现在 CursorAdapter 似乎没有 notifyDataSetChanged() 方法,所以我复制了与 BaseAdapter 相同的代码逻辑并在我的中使用它。较低的 Coverflow 仍然使用相同的适配器(在本例中为 ListAdapter,实现了 SpinnerAdapter)。现在 - 当执行完全相同的逻辑时,在中心 CoverFlowAdapter 上的每个 notifyDataSetChanged() 调用之后,下部 Coverflow 会自行居中。我真的不明白。我不会在这里发布整个逻辑,因为那将是大约 5 个类,但问题在于这一点:

   private OnItemSelectedListener itemSelListener = new OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
//          if(!selectedByClicking){
            switchModelType(arg1.getId());          
//          }
    }

private void switchModelType(int id){
    int oldMode = mode;
    mode = id;
    for(int i = 0; i < currentColors.length; i++){
        if(currentColors[i] != null)
        currentColors[i].isSelected = false;
    }
    if(currentColors[mode] != null)
    currentColors[mode].isSelected = true;
    if(coverFlow.getAdapter() != null){
        ((SelectionObjectCursorAdapter)     
            coverFlow.getAdapter()).notifyDataSetChanged();
             //         if(decorIsWooden)
             //             checkIfWoodDecorAdapter(oldMode);

    }
}

在这部分代码的任何一点都没有触及下部的 CoverFlow,也没有在类中的任何地方触及。

【问题讨论】:

    标签: android gallery coverflow baseadapter android-cursoradapter


    【解决方案1】:

    没关系.. 虽然我搜索了这个错误好几天,但我现在找到了解决方案。

    问题是,我以编程方式创建了较低的封面流,因此以编程方式使用 layout_height 设置两者的高度。每次我更改coverflow的适配器时,它都会调用它的measure方法,因此也会调用下部coverflow的measure方法(因为它们是通过layout_height链接的)。在 XML 中设置这个,将 layout_sum 添加到超线性布局就解决了这个问题。

    感谢上帝..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      相关资源
      最近更新 更多