Cocos2d-x3.3final (1) ListView Common member function (c + +)

Source: Internet
Author: User
Tags set background

ListView ListView = Listview::create (); --Create a list

Listview->setdirection (Ui::scrollview::D irection::vertical); --set list orientation

Listview->setbounceenabled (TRUE); --Set stretch

Listview->setbackgroundimage ("Cocosui/green_edit.png"); --Set background image

Listview->setbackgroundimagescale9enabled (TRUE); --set whether to allow nine lattice

Listview->setcontentsize (Size (a); --Set size

Listview->setposition (VEC2 ());

Listview->addeventlistener ((Ui::listview::cclistviewcallback) Cc_callback_2 (class name:: Callback function 1, this)); //Register event handler function

Listview->addeventlistener ((Ui::listview::ccscrollviewcallback) Cc_callback_2 (class Name: callback function 2, this)); //Register event handler function

void class Name:: Callback function 1 (REF * psender, Listview::eventtype type) --Note the parameter type here

{

Switch (type)

{

Case Cocos2d::ui::listview::eventtype::on_selected_item_start:

ListView * ListView = Static_cast (ListView *) (Psender);

Listview->getcurselectedindex ();

Break

Case Cocs2d::ui::listview::eventtype::on_selected_item_end:

ListView * ListView = Static_cast (ListView *) (Psender);

Listview->getcurselectedindex ();

Break

Default

Break

}

}


void class Name:: Callback function 2 (REF * psender, Ui::scrollview::eventtype type)

{

Switch (type)

{

Case Ui::scrollview::eventtype::scroll_to_bottom:

Break

Case Ui::scrollview::eventtype::scroll_to_top:

Break

Default

Break

}

}


Layout * Default _item = Layout::create (); //Create model

Listview->setitemmodel (Default_item); //Setup Model


Listview->pushbackdefaultitem (); //Add default Element

Listview->insertdefaultitem (index); //insert default Element

Layout * Custom_item = Layout::create ();

Listview->addchild (Custom_item); //Add regular elements

Listview->insertcustomitem (Custom_item, index) //Insert Regular element

vector<widget*>& items = Listview->getitems (); Returns the container that holds the element

widget* item = Listview->getitem (i); //Get an element of an index

ssize_t index = Listview->getindex (item); //Gets the index of an element

Listview->removechildbytag (1); //functions that inherit from Ccnode

Listview->removeitem (items_count-1); //Delete an element of an index

Listview->setgravity (listview::gravity::center_vertical); Set Gravity

Listview->setitemsmargin (2.0f); //Change the boundary between two elements



Cocos2d-x3.3final (1) ListView Common member function (c + +)

Related Article

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.