Android Imitation Taobao view slide to the top of the screen will always stay at the top position _android

Source: Internet
Author: User

In the project just completed, in a page, user experience Division to put forward the user operation of the stay button to remain in the page, no matter how long the page can be scrolled to stay in the visual area of the page. The final implementation effect is shown in the following illustration:

The view in the red box in the picture always stays on the page, and if you slide to the top of the page, it remains at the top.

The following specific implementation ideas:

Idea: In fact, the whole page has a total of two visual effects of the same view, by sliding the location of the view to hide and display to achieve this effect. The entire page can be summarized in two states in the process of sliding up and down, state a (as shown in Figure 1), view2 in the viewable area, view1 not visible. State B (as shown in Figure 2), view2 slides over the viewable area, which is view1 visible and view2 invisible.

View display and Hidden time: 1, when the page slide up, from state A to State B of the moment, view1 just slide to the top and view2 coincide with the moment, will view1 display;

2, when the page slide down, from State B to the moment of state A, view2 just and view1 coincide with the moment, will view1 hidden.

Viewallshowlinearlayout class

Package org.sunday.uiext; 
Import Android.content.Context; 
Import Android.util.AttributeSet; 
Import Android.view.View; 
Import Android.widget.LinearLayout; 
Import Android.widget.ScrollView; /** * @author Sunday * 2013-12-5 * Email: zhengchao1937@163.com * qq:804935743/public class Viewallshowlinearlayout E Xtends LinearLayout {Private View Mview//Top view private Viewswitchlistener viewswitchlistener;//external Hook interface private S 
Crollview Mscrollview; Private Boolean isflag = true; Auxiliary judgment Variable public void InitData (view view, ScrollView ScrollView, Viewswitchlistener viewswitchlistener) {This.mview = V 
Iew; 
This.mscrollview = ScrollView; 
This.viewswitchlistener = Viewswitchlistener; 
Public Viewallshowlinearlayout {Super (context); 
Init (); 
Public Viewallshowlinearlayout (context, AttributeSet attrs) {Super (context, attrs); 
Init (); 
private void Init () {setorientation (linearlayout.vertical); @Override public void Computescroll () {iF (mview!= null && mscrollview!= null && viewswitchlistener!= null) {int y = mscrollview.getscrolly () 
; 
if (isflag) {int top = Mview.gettop (); 
if (y >= top) {viewswitchlistener.onviewshow (); 
Isflag = false; 
} if (!isflag) {int bottom = Mview.getbottom (); 
if (y <= bottom-mview.getheight ()) {viewswitchlistener.onviewgone ()); 
Isflag = true; 
Public interface Viewswitchlistener {public void onviewshow (); 
public void Onviewgone (); } 
}

Use effects in projects:

The above is a small set to introduce the Android imitation Taobao view slide to the top of the screen will always stay at the top of the position, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.