High profile app, floating layout slide to top hover effect

Source: Internet
Author: User

Made a similar effect to the American group app.

When a floating layout is sliding to the top, the floating layout hovers down and the floating layout moves down as the screen slides down.

So, I specifically wrote a: floating layuot slide to the top hover demo,:

(Mom eggs upload pictures can not exceed 200k, only to the picture castrated so, make a look at it)

Principle
Well, after reading, let's look at the design of this effect.
First, let's take a look at the overall design:

The design is divided into three parts: the top area, the floating area A, and the list area.
1. When the screen slides above, the interactive area A also follows the slide;
2. When the floating area A is sliding to the top, the floating area a stays at the top (upper right);
3. When the screen slides down, the floating area a also slides down.
This is the entire slide effect flow.

So, here comes the question. How can a floating area a stop at the top without affecting other content sliding?


Here we can write more than one and floating area A interface effect is exactly the same as the floating area B. In the layout, we first set the visibility of the floating area B to gone, which is hidden. When the floating area A is sliding to the top, the visibility of the floating area B is set to visible. At this point, the floating area B will cover the entire screen, even if the whole screen will not affect the position of the floating area B when it is sliding, then it looks as if the floating area A is stuck in the top position, see.

(At this point, the visibility of the set floating area B is visible.)

Similarly, when the entire screen slides down and then sets the visibility of the floating area B to gone, the effect looks as if the floating area A is sliding again.

This principle should be understood by everyone!

Implementation process
After saying the principle, let's look at how this process is implemented in the code.
Let's look at the layout file first Activity_main.xml

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Tools:context= ". Mainactivity ">

<com.jimstin.topfloatdemo.view.myscrollview
Android:id= "@+id/scroll_view"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Vertical" >
<imageview
Android:id= "@+id/image_view"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:background= "@drawable/pic01"/>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal"
android:background= "#f6e4c0" >
<textview
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
Android:textsize= "10pt"
android:text= "Cola chicken wings 55 yuan"
Android:textcolor= "#e68b4e"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Buy Now"
Android:textcolor= "#ffffff"/>
</LinearLayout>
<listview
Android:id= "@+id/list_view"
Android:layout_width= "Match_parent"
android:layout_height= "0DP"
android:layout_weight= "1" >

</ListView>

</LinearLayout>
</com.jimstin.topfloatdemo.view.MyScrollView>

<linearlayout
Android:id= "@+id/flow_llay"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal"
Android:background= "#f6e4c0"
Android:visibility= "Gone" >
<textview
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
Android:textsize= "10pt"
android:text= "Cola chicken wings 55 yuan"
Android:textcolor= "#e68b4e"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Buy Now"
Android:textcolor= "#ffffff"/>
</LinearLayout>
</RelativeLayout>

Layout file effects

The top of the "Cola chicken wings" is just said floating area B, the middle of the "Cola Chicken Wings" is a floating area A, layout files should not be difficult to understand.
So how do we know when to hide and show the floating layout at the top?

because the overall layout content is placed in a custom scrollview inside. So, as long as we judge in ScrollView:
      When the ScrollView upward slide is greater than the height of the top area, that is, when the top edge of the floating area A is pasted to the top of the screen, the visibility of the floating area B is set to visible, otherwise it is set to gone.
This will achieve the effect we want.
Key code:

@Override
protected void onscrollchanged (int l, int t, int oldl, int Oldt) {

Super.onscrollchanged (L, T, OLDL, Oldt);
if (Mtopview! = null) {
if (t >= mtopview.getheight ()) {
Mflowview.setvisibility (view.visible);
} else {
Mflowview.setvisibility (View.gone);
}
}
}

code means that when the height of the scrollview upward scroll is greater than or equal to the height of the Mtopview top area, The visibility of the Mflowview floating layout is set to visible, otherwise it is set to gone.
So where is this interpretation?


In fact, this method is in the custom scrollview inside, perhaps there is some doubt, why do you want to customize the ScrollView? Because the Onscrollchange method is a protected method, using ScrollView directly is not the way to use it.

All right, today's share is over!

If you like, please support my blog articles, I will try to spare time to share dry!! Tender support is the power of benevolence home!!!

1 want to make a profit? Think, that's right.

2 Android Development Make money

This is in my blog the highest clickthrough rate of two articles, it seems that we are still interested in making money, there is a need for friends can go to see, no thanks, I am Lei Feng, hehe!!!

High profile app, floating layout slide to top hover effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.