Android controls the height of ListView by sliding

Source: Internet
Author: User
First, look at the picture:
When you slide up and down the area marked with the red frame, change the height of the ListView,
Start
1, to obtain ListView Layoutparams:
Layoutparams params= listview.getlayoutparams ();
2, for the Relativelayout set gesture monitoring:
Mrlbus.setontouchlistener (New View.ontouchlistener () {//mrlbus is the outer layout of the red box
Float y=0;//defines a y here, receives the y-coordinate
@Override
public boolean Ontouch (View V, motionevent event) {
Switch (event.getaction ()) {
Case Motionevent.action_down:
Y=event.gety ()///////////////////////////////
Break
Case Motionevent.action_move:
Float x= event.gety ()-y;//This defines an X, meaning that each moment of the slide, the ordinate of the current moment minus the ordinate of the first finger
if (x>0| | PARAMS.HEIGHT<=250) {//If the finger is downward (x=0) or the height of the ListView is less than 250,
params.height= (int) (params.height-x); Perform a lower or elevated listview operation
if (params.height>250) {//The meaning of this step is: Assume the user is very fast up and down, may cause a height greater than 250
params.height=250;//if too high, then fixed to 250
}
}
if (params.height<0) {//The meaning of this step is: Assume the user is very fast to fall, may cause a height of less than 0, causing ListView to choose the height before sliding is the current height
params.height=0;
}
Listview.setlayoutparams (params);
Break
Case MOTIONEVENT.ACTION_UP:
Break
}
return true;
}
});
If you can help the audience, just a little bit of praise.

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.