简体   繁体   中英

how to make a scroll view to scroll over another layout with the layout behind staying intact but behind scroll content

如何使滚动视图滚动到另一个布局上,而后面的布局保持不变,但在滚动内容后面我的要求是应用程序的标题将保持固定,而如果其中的内容足够大可以滚动,则它下面的布局将滚动,请提供给我或建议任何解决此问题的方法

Try this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="100dp">

        <LinearLayout
            android:layout_width="269dp"
            android:layout_height="match_parent"
            android:orientation="vertical">

           <!-- any no. of views here -->
        </Linearlayout>
    <ScrollView>
</Linearlayout>

Add this code to onCreate():

scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {

                @Override
                public void onScrollChanged() {
                    Layout.setY(Layout.getY() + scrollView.getScrollY() - Layout.getY());


                }
            });

Every time the view is scrolls, the layout will move the opposite value. Which looks like it's not moving at all. Make sure all your views are inside the ScrollView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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