简体   繁体   中英

How to scroll layout with header and FrameLayout

I have a view that show header with text and logo and button of this layout shows details. How can i change height of header when user scroll this page?

my layout:

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:gravity="right"
        android:id="@+id/rlBrand"
        android:background="@drawable/brand_back">
        <ImageView
            android:layout_marginRight="30dp"
            android:id="@+id/imgBrandLogoAct"
            android:layout_width="100dp"
            android:src="@drawable/ic_launcher"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/txtBrandTitleAct"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="سامسونگ"
            style="@style/AudioFileInfoOverlayText"
            android:textStyle="bold"
            android:layout_marginRight="20dp"
            android:layout_toLeftOf="@+id/imgBrandLogoAct"
            android:textColor="@color/white"
            />
        </RelativeLayout>
    <FrameLayout android:layout_gravity="right" android:id="@+id/containerBrand" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_alignParentBottom="true" />
    </RelativeLayout>
</ScrollView>

我的布局

i want header go thiner when user scroll.

salam refigh. I think this method will work for you. Use scrollX & scrollY for adjusting your header.

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

    @Override
    public void onScrollChanged() {

        int scrollX = rootScrollView.getScrollX(); //for horizontalScrollView
        int scrollY = rootScrollView.getScrollY(); //for verticalScrollView
        //DO SOMETHING WITH THE SCROLL COORDINATES

    }
});

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