【问题标题】:How to display Activity with 3 fragments in scrolling ListView?如何在滚动 ListView 中显示带有 3 个片段的 Activity?
【发布时间】:2014-11-22 06:55:31
【问题描述】:

我有一个Activity,其中包含 3 个Fragments。并且所有 3 个 Fragments 中都有 ListView

我想知道如何在同一Activity 中显示ScrollView 中的3 个Fragments?

请告诉我解决方案。

谢谢。

【问题讨论】:

  • 你有什么尝试?你不能在 ScrollView 中使用 ListView。
  • 不,我没有使用滚动列表只是列表视图
  • @Riad 您提供的链接有使用代码调用的片段,而我们使用 xml 调用了片段。有什么想法吗?
  • 将同向滚动的视图放在一起并不能带来良好的用户体验。

标签: android listview android-fragments fragment listadapter


【解决方案1】:

所以我认为正确的用户体验是只有 1 个滚动视图,即基本滚动视图。然后,片段中的列表视图应展开以占用所需的空间。

我做到这一点的方法是像这样覆盖 onMeasure

@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) {
  /**
   * Putting things which like to be scrolled into scrolling views causes bad behavior.
   *
   * The goal here is to simply trick the List view into believing it should fill all available
   * space rather than being undefined.
   */
  heightMeasureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

这样你就有了 1 个可滚动视图和 3 个展开的列表视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-01
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多