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!