繁体   English   中英

如何在android中制作一个贴在屏幕底部的布局,直到scrollview滚动到某个位置时它也会滚动?

[英]How to make a layout in android that sticks to the bottom of the screen until the scrollview is scrolled to a certain position it gets scroll too?

我想制作一个android活动屏幕,在该屏幕上将布局固定在底部,直到scrollview滚动到某个位置。 像此视频示例链接中一样:

https://drive.google.com/open?id=0B14wNBitoI33LWtUNThqcXRIUWc

https://drive.google.com/open?id=0B14wNBitoI33QW1BOGR1di1TcGc

使用RelativeLayout并将Button-Container放入其中。 在your_scrollview_activity.xml中将以下属性传递给容器

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 1 (reft)" />

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 2 (right)"/>

    </LinearLayout>

</RelativeLayout>

注意:您需要在活动中设置一个侦听器,以获取ScrollViews的当前位置/当前高度。 使用此当前高度,您可以计算ScrollView的底部/末端的“左侧空间”。 如果您的RelativeLayout到达底部或在可见区域内靠近底部AND ,则调用动画。

amarjain07的StickyScrollView也许是您想研究的解决方案。 他在布局xml中将“粘性”视图分配为已标识属性的方法是非常不错的功能,恕我直言。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM