編輯:關於Android編程
感覺android中的toast效果挺不錯的,就試著自己用2dx做了一下,挺簡單的,效果也不錯。
XYToast.h
#pragma once #include "cocos2d.h" #include "cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; using namespace std; class XYToast: public CCLayerColor { public: CCSize visibleSize; CCPoint origin; CCScale9Sprite* bg; public: XYToast(); ~XYToast(); void removeSelf(); virtual bool init(); void initToast(string msg,float time); CREATE_FUNC(XYToast); void onExit(); };
XYToast.cpp
#include "XYToast.h" XYToast::XYToast() { } XYToast::~XYToast() { } bool XYToast::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayerColor::initWithColor(ccc4(0, 0, 0, 0)));//ccc4(0, 0, 0, 125) visibleSize = CCDirector::sharedDirector()->getVisibleSize(); origin = CCDirector::sharedDirector()->getVisibleOrigin(); //==================================== bg = CCScale9Sprite::create("toast_bg.png"); bg->setPosition(ccp(origin.x+visibleSize.width/2,origin.y+130*visibleSize.height/960)); //============================ bRet = true; } while (0); return bRet; } void XYToast::onExit() { CCLayerColor::onExit(); } void XYToast::initToast( string msg,float time ) { CCLabelTTF* pLabel = CCLabelTTF::create(msg.c_str(), "Arial", 21); pLabel->setColor(ccWHITE); bg->setContentSize(CCSizeMake(pLabel->getContentSize().width+10,pLabel->getContentSize().height+10)); bg->addChild(pLabel, 1); this->addChild(bg,10); pLabel->setPosition(ccp(bg->getContentSize().width/2,bg->getContentSize().height/2)); pLabel->runAction(CCSequence::create(CCFadeIn::create(time/5), CCDelayTime::create(time/5*3),CCFadeOut::create(time/5),NULL)); bg->runAction(CCSequence::create(CCFadeIn::create(time/5), CCDelayTime::create(time/5*3),CCFadeOut::create(time/5), CCCallFunc::create(this,callfunc_selector(XYToast::removeSelf)),NULL)); //========================= //this->scheduleOnce(schedule_selector(XYToast::removeSelf),time); } void XYToast::removeSelf() { this->removeFromParentAndCleanup(true); }
調用方法
XYToast* toast = XYToast::create(); toast->initToast(Tools::a2u("登錄成功").c_str(),2.5f); this->addChild(toast,10);
背景圖
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+1NnTw76yzKy3vbeo0LTSu7j2o6zSu9H5tcTQp7n7o6y199PDuPy807e9seM8L3A+CjxwPlRvb2xzLmg8L3A+CjxwPjxwcmUgY2xhc3M9"brush:java;"> static void showToast(CCLayer*layer,string msg,float dt);
void removeToast(CCNode* node);Tools.cpp
void Tools::showToast(CCLayer*layer, string msg,float dt ) { CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCScale9Sprite* bg = CCScale9Sprite::create("toast_bg.png"); bg->setPosition(ccp(origin.x+visibleSize.width/2,origin.y+130*visibleSize.height/960)); CCLabelTTF* pLabel = CCLabelTTF::create(msg.c_str(), "Arial", 21); pLabel->setColor(ccWHITE); bg->setContentSize(CCSizeMake(pLabel->getContentSize().width+10,pLabel->getContentSize().height+10)); bg->addChild(pLabel, 1); layer->addChild(bg,10); pLabel->setPosition(ccp(bg->getContentSize().width/2,bg->getContentSize().height/2)); pLabel->runAction(CCSequence::create(CCFadeIn::create(dt/5), CCDelayTime::create(dt/5*3),CCFadeOut::create(dt/5),NULL)); bg->runAction(CCSequence::create(CCFadeIn::create(dt/5), CCDelayTime::create(dt/5*3),CCFadeOut::create(dt/5), CCCallFuncN::create(bg,callfuncN_selector(Tools::removeToast)), NULL)); } void Tools::removeToast(CCNode* node) { node->removeFromParentAndCleanup(true); }
Tools::showToast(this,"error",3.0f);
在Android開發時,我們使用的大部分都是Java的api,比如HashMap這個api,使用率非常高,但是對於Android這種對內存非常敏感的移動平台,很多時候使用
Android TextView 圓弧效果圖:布局代碼:<TextView android:id=@+id/product_tag
目錄概述StickHeaderItemDecoration是用於顯示固定頭部的item裝飾類,擴展來自系統的ItemDecoration.本文參考了一部分sticky-h
1. Adapter.getView() public View getView(int position, View convertView , ViewGroup p