【问题标题】:Suggestions on how to implement this layout on android关于如何在 android 上实现此布局的建议
【发布时间】:2014-10-22 16:20:26
【问题描述】:

这就是我想要的:

我的布局有 3 个主要布局,其中都有 TextViews 和 ImageViews。

  • 黄色布局始终保持在同一位置

  • 随着用户滚动列表,绿色布局将慢慢开始向上/向下移动。当它到达屏幕顶部时,它将保持粘性,允许列表滚动。向后滚动时,会向下滚动到原来的位置,然后停止。

  • 红色黄色是列表视图。

  • 当列表向上滚动时,用户仍然可以点击黄色布局上的按钮

我应该如何实现这个?我想到的第一件事是 FrameLayout,以便允许布局重叠。对于绿色布局,我认为https://github.com/emilsjolander/StickyListHeaders 之类的东西可能会起作用。但是列表滚动呢?

【问题讨论】:

  • 也许这有帮助:如果这有效:sdchang.com/wordpress/2014/03/10/… 你可以为第一层创建一个线性视图,然后将 PinnedSectionListView 放在它上面的片段中

标签: android android-layout android-framelayout


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp" 
        android:layout_gravity="bottom"/>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginTop="100dp" />

</FrameLayout>

以编程方式,使用列表的大小和项目高度来设置按钮的下边距。

【讨论】:

  • 请注意,ListView 的“marginTop”是按钮的高度。
  • 我尝试检测列表的滚动方向并根据滚动偏移量增加/减少 marginTop。长话短说,当用户向上滚动时,这种情况会发生,但是,当向后滚动时,列表不会触发 onScroll 因为第一项已经可见......所以我无法将列表向下移动到原始位置。
【解决方案2】:

最后,我采用了受 http://flavienlaurent.com/blog/2013/11/20/making-your-action-bar-not-boring/ 启发的实现,它确实符合我的目的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多