【问题标题】:Footerview not displaying always when scrolling the listview滚动列表视图时,页脚视图不总是显示
【发布时间】:2014-10-13 22:57:28
【问题描述】:

我有一个带有适配器的列表视图。我想添加一个页脚,并且滚动列表视图时将显示此页脚。现在使用此代码,当列表视图完成时将显示页脚视图。在列表的 onCreate 方法中,我有:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listado_imagenes_subidas_main);

    // load list application
    listImagenes = (ListView)findViewById(R.id.lvImages);

    LayoutInflater inflater = getLayoutInflater();
    ViewGroup footer = (ViewGroup) inflater.inflate(R.layout.footer3buttons, listImagenes,
            false);
    listImagenes.addFooterView(footer, null, false);

    // create new adapter
    ImagenesAdapter adapter = new ImagenesAdapter(this, ListadoImagenes());
    // set adapter to list view
    listImagenes.setAdapter(adapter);
}

你能帮我解决这个问题吗?

先谢谢你了。

【问题讨论】:

  • 如果您想要一个始终显示在屏幕上的页脚视图,您需要将该视图放在您的布局中ListView 下方。如果您希望页脚与列表一起滚动(因此它在适配器中的最后一项之后显示为列表项),请使用addFooterView()
  • 我该怎么做?有例子吗?
  • 使用列表视图时如何始终在屏幕上显示页脚视图的示例

标签: android android-listview footer


【解决方案1】:

如果我正确理解您不想要的是“粘性”页脚,addFooterView 方法在最后一个视图项之后添加页脚,对于粘性页脚,您必须自己滚动,或使用外部库.

【讨论】:

  • 我该怎么做?有例子吗?
【解决方案2】:

试试这个

View footerView =  ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
list.addFooterView(footerView);

【讨论】:

  • 在设置适配器之前不要忘记调用这个方法。
猜你喜欢
  • 2022-01-16
  • 2017-01-28
  • 1970-01-01
  • 2011-12-08
  • 2015-04-17
  • 2019-04-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-21
相关资源
最近更新 更多