Android ScrollView Scrolling to achieve popular reviews, NetEase cloud music commentary hover effect

Source: Internet
Author: User

Today listen to NetEase cloud Music, write code, really cool turned.


http://blog.csdn.net/linshijun33/article/details/47910833
NetEase Cloud Music This product highlight should be in the review of this module, so I went to see the next comment area, found a it is used by a scrollview, from top to bottom can be divided into three parts. The top is the music cover . Next is a wonderful review , followed by the latest commentary . The finger scrolls a distance above it. great reviews hover over the top of the layout, then scroll, and the latest reviews take the place of great reviews hovering over the top of the layout, a very interesting feature.

And then went over the mass review app and found that it was also applied to this hover effect.

The price display hovers over the top.
This one is really a very hard move. Price consumers are always able to see. How good the user experience, can be very good to improve the conversion rate of products. That's witty.
Do take a bit of effort on user interaction.

So think about how to achieve this effect. To find the information to see. That's probably how it's done.

The usual, first.



then hover, and the picture is intercepted. A little deformed.

First on the layout file Activity_main.xml, set the control has four, a self-defined Myscrollview (code behind the layout), two ImageView, a textview (used to fill the space for the screen to scroll up).

Activity_main.xml
<relativelayout xmlns:android="Http://schemas.android.com/apk/res/android" xmlns:tools="Http://schemas.android.com/tools"android:id="@+id/box"  Android:layout_width="Match_parent"android:layout_height="Match_parent" Tools:context=". Mainactivity ">                        <com.topfloat.MyScrollViewandroid:id="@+id/myscrollview"android:layout_ Width="Fill_parent"android:layout_height="Match_parent">                                <linearlayoutandroid:layout_width="Match_parent"android:layout_ Height="Wrap_content"android:orientation="vertical">                                                <relativelayout  andr Oid:id  = "@+id/rlayout"  android:layout_wi DTH  = "fill_parent"  android:layout_height  = "wrap_content" ;                 <ImageViewandroid:id= "@+id/top"android:layout_width="Fill_ Parent "android:layout_height="wrap_content "android:background="@mipmap/top _show "android:layout_alignparentbottom=" true " />                                                                                                                </relativelayout>            <linearlayout  androi D:id  = "@+id/bind_2"  android:layout_width  = "match_parent"  android:layout_height
      = "wrap_content"  android:orientation= "vertical" ;                 <ImageViewandroid:id= "@+id/buy_price"android:layout_width="Fill _parent "android:layout_height=" Wrap_content "android:background=" @mipmap/ Buy_price " />                                                                                            </linearlayout>            <textview  android:la Yout_width  = "match_parent"  android:layou T_height  = "wrap_content"  android:gravity  = "center_horizontal"  android:text= "below the contents of their own brain repair \ \ The following contents of their own brain repair \ \ The following contents of their own brain repair \ \ The following contents of their own brain repair \ \ \ \ \ \ \ \ 's contents below The contents of their own brain repair \ \ The following contents of their own brain repair \ \ The following contents of their own brain fill \ \ The following contents of their own brain fill \ \ The following contents of their own brain fill \ \ Below the contents of their own brain fill \ \ Below the contents of their own brain fill \                 Brain repair \ nthe contents of the following their own brain repair \ \ The following contents of their own brain repair \ \ The following contents of their own brain repair \ \ The following contents of their own brain repair \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ " android:textsize  = "30sp" />         </linearlayout>    </com.topfloat.MyScrollView>    <linearlayoutandroid:id= "@+id/bing_1"android:layout_width=" Match_parent "android:layout_height=" Wrap_content "android:orientation= "vertical">                                    </linearlayout></relativelayout>

And then gives you a definition of the control Myscrollview

Myscrollview
 PackageCom.topfloat;/** * Created by Linshijun on 2015/8/23. * *ImportAndroid.content.Context;ImportAndroid.os.Handler;ImportAndroid.util.AttributeSet;ImportAndroid.view.MotionEvent;ImportAndroid.widget.ScrollView;/ * * ScrollView does not implement scrolling monitoring. So we have to monitor the ScrollView on our own. * It's very natural to think of the Ontouchevent () method to monitor the rolling y-axis for listening * ScrollView The rolling y-value of the * * * Public  class myscrollview extends ScrollView {    PrivateOnscrolllistener Onscrolllistener;/** * is mainly used on the user's finger to leave the myscrollview. Myscrollview continues to slide, we use to save the Y distance, and then do the comparison * /    Private intlastscrolly; Public Myscrollview(Context context) {Super(Context,NULL); } Public Myscrollview(context context, AttributeSet attrs) {Super(Context, Attrs,0); } Public Myscrollview(context context, AttributeSet attrs,intDefstyle) {Super(Context, attrs, Defstyle); }/** * Set Scrolling interface * * @param onscrolllistener */     Public void Setonscrolllistener(Onscrolllistener Onscrolllistener) { This. Onscrolllistener = Onscrolllistener; }/** * Used to get the y distance of Myscrollview scrolling when the user fingers leave Myscrollview. Then callback to the Onscroll method * /    PrivateHandler Handler =NewHandler () { Public void Handlemessage(Android.os.Message msg) {intscrolly = Myscrollview. This. getscrolly ();//The distance at this time is not equal to the recorded distance, sending a message to handler in 5 milliseconds            if(lastscrolly! = scrolly)                {lastscrolly = scrolly; Handler.sendmessagedelayed (Handler.obtainmessage (),5); }if(Onscrolllistener! =NULL) {Onscrolllistener.onscroll (scrolly); }        }    };/** * Rewrite ontouchevent.     When the user's hand is above the Myscrollview, the * directly myscrollview the y-direction distance of the slide to the Onscroll method, when the user lifts his hands. * The Myscrollview may still be sliding. So when the user lifts up our hands we send a message to handler at 5 milliseconds, the distance in handler processing * myscrollview sliding * /    @Override     Public Boolean ontouchevent(Motionevent ev) {if(Onscrolllistener! =NULL) {Onscrolllistener.onscroll (lastscrolly = This. getscrolly ()); }Switch(Ev.getaction ()) { CaseMotionEvent.ACTION_UP:handler.sendMessageDelayed (Handler.obtainmessage (),5); Break; }return Super. ontouchevent (EV); }/** * Scrolling Callback interface * /     Public  interface onscrolllistener {        /** * callback method. Returns the Y-direction distance of the Myscrollview slide * /         Public void onscroll(intscrolly); }}

ScrollView does not implement the rolling monitoring, so it is necessary to implement the monitoring of the ScrollView, because the direction of scrolling in the y-axis, you can use the Ontouchevent () method to monitor the rolling y-axis, while the finger left the screen, scrolling continues, At this point, you have to choose to infer whether the scrollview stops sliding every 5 milliseconds when the user's finger leaves. The ScrollView scroll y value is called back to the onscroll (int scrolly) method of the Onscrolllistener interface.

You can then call the Setonscrolllistener method on the ScrollView to hear the scrolling Y-value.

Realized the above two steps. The mainactivity is simpler. The main use of the control's dependencies to AddView and Removeview, so that the code is more concise, more applicability.

Mainactivity
 PackageCom.topfloat;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.widget.ImageView;ImportAndroid.widget.LinearLayout;ImportAndroid.widget.RelativeLayout;/** * Implement Onscrolllistener interface * / Public  class mainactivity extends appcompatactivity  implements  Myscrollview. Onscrolllistener {    PrivateImageView topshow,priceshow;PrivateMyscrollview Myscrollview;Private intBuypricetop;    LinearLayout bind_1,bind_2; Relativelayout rlayout;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);//Initialize controlInitview (); }Private void Initview() {topshow= (ImageView) Findviewbyid (r.id.top);        priceshow= (ImageView) Findviewbyid (R.id.buy_price);        myscrollview= (Myscrollview) Findviewbyid (R.id.myscrollview);        rlayout= (relativelayout) Findviewbyid (r.id.rlayout);        bind_1= (LinearLayout) Findviewbyid (r.id.bing_1);        Bind_2= (LinearLayout) Findviewbyid (r.id.bind_2); Myscrollview.setonscrolllistener ( This); }/** * Gets the top position of the pirce_show, which is the bottom position of the rlayout * @param hasfocus */    @Override     Public void onwindowfocuschanged(BooleanHasfocus) {Super. onwindowfocuschanged (Hasfocus);if(Hasfocus) {Buypricetop=rlayout.getbottom ();//Get the top position of the pirce_show. The bottom position of the rlayout}    }@Override     Public Boolean Oncreateoptionsmenu(Menu menu) {//inflate the menu; This adds items to the action bar if it is present.Getmenuinflater (). Inflate (R.menu.menu_main, menu);return true; }@Override     Public Boolean onoptionsitemselected(MenuItem Item) {//Handle Action Bar item clicks here. The Action Bar would        //automatically handle clicks on the Home/up button, so long        //As you specify a parent activity in Androidmanifest.xml.        intid = item.getitemid ();//noinspection simplifiableifstatement        if(id = = r.id.action_settings) {return true; }return Super. onoptionsitemselected (item); }/** * Monitor scrolling y-value changes. Hover effect via AddView and Removeview * @param scrolly */    @Override     Public void onscroll(intscrolly) {//Infer whether the scrolling distance is the height of the picture        if(Scrolly>=buypricetop) {if(Priceshow.getparent ()!=bind_1)//Infer its existing parent class{Bind_2.removeview (priceshow);//Remove from existing parent classBind_1.addview (priceshow);//Join to target parent class}        }Else{if(Priceshow.getparent ()!=bind_2)                {Bind_1.removeview (priceshow);            Bind_2.addview (priceshow); }        }    }}

The basic point of gaze will need to be said, better understand.

Android Studio Source code will be uploaded later, there is a need to be able to download to see.


http://download.csdn.net/detail/linshijun33/9039237

Android ScrollView Scrolling to achieve popular reviews, NetEase cloud music commentary 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.