一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務(wù)器之家 - 編程語言 - JAVA教程 - java實(shí)現(xiàn)菜單滑動(dòng)效果

java實(shí)現(xiàn)菜單滑動(dòng)效果

2019-12-14 15:05hebedich JAVA教程

這篇文章主要介紹了java實(shí)現(xiàn)菜單滑動(dòng)效果,效果非常棒,這里推薦給大家,有需要的小伙伴可以參考下。

菜單滑動(dòng)效果的實(shí)現(xiàn)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
public class MenuScrollerActivity extends BaseGameActivity implements IScrollDetectorListener, IOnSceneTouchListener, IClickDetectorListener {
    
    // ===========================================================
    // Constants
    // ===========================================================
    protected static int CAMERA_WIDTH = 480;
    protected static int CAMERA_HEIGHT = 320;
 
    protected static int FONT_SIZE = 24;
    protected static int PADDING = 50;
     
    protected static int MENUITEMS = 7;
     
 
    // ===========================================================
    // Fields
    // ===========================================================
    private Scene mScene;
    private Camera mCamera;
 
    private Font mFont;
    private BitmapTextureAtlas mFontTexture;  
     
    private BitmapTextureAtlas mMenuTextureAtlas;   
    private TextureRegion mMenuLeftTextureRegion;
    private TextureRegion mMenuRightTextureRegion;
     
    private Sprite menuleft;
    private Sprite menuright;
 
    // Scrolling
    private SurfaceScrollDetector mScrollDetector;
    private ClickDetector mClickDetector;
 
    private float mMinX = 0;
    private float mMaxX = 0;
    private float mCurrentX = 0;
    private int iItemClicked = -1;
     
    private Rectangle scrollBar;   
    private List<TextureRegion> columns = new ArrayList<TextureRegion>();
 
    // ===========================================================
    // Constructors
    // ===========================================================
 
    // ===========================================================
    // Getter & Setter
    // ===========================================================
 
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================
 
    @Override
    public void onLoadResources() {
        // Paths
        FontFactory.setAssetBasePath("font/");
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
 
        // Font
        this.mFontTexture = new BitmapTextureAtlas(256, 256);
        this.mFont = FontFactory.createFromAsset(this.mFontTexture, this, "Plok.TTF", FONT_SIZE, true, Color.BLACK);
        this.mEngine.getTextureManager().loadTextures(this.mFontTexture);
        this.mEngine.getFontManager().loadFonts(this.mFont);
         
        //Images for the menu
        for (int i = 0; i < MENUITEMS; i++) {       
          BitmapTextureAtlas mMenuBitmapTextureAtlas = new BitmapTextureAtlas(256,256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
          TextureRegion mMenuTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuBitmapTextureAtlas, this, "menu"+i+".png", 0, 0);
           
          this.mEngine.getTextureManager().loadTexture(mMenuBitmapTextureAtlas);
          columns.add(mMenuTextureRegion);
           
           
        }
        //Textures for menu arrows
        this.mMenuTextureAtlas = new BitmapTextureAtlas(128,128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.mMenuLeftTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTextureAtlas, this, "menu_left.png", 0, 0);
        this.mMenuRightTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTextureAtlas, this, "menu_right.png",64, 0);
        this.mEngine.getTextureManager().loadTexture(mMenuTextureAtlas);
      
    }
 
    @Override
    public Engine onLoadEngine() {
        this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
 
        final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new FillResolutionPolicy(), this.mCamera);
        engineOptions.getTouchOptions().setRunOnUpdateThread(true);
 
        final Engine engine = new Engine(engineOptions);
        return engine;
    }
 
    @Override
    public Scene onLoadScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());
 
        this.mScene = new Scene();
        this.mScene.setBackground(new ColorBackground(0, 0, 0));
        
        this.mScrollDetector = new SurfaceScrollDetector(this);
        this.mClickDetector = new ClickDetector(this);
 
        this.mScene.setOnSceneTouchListener(this);
        this.mScene.setTouchAreaBindingEnabled(true);
        this.mScene.setOnSceneTouchListenerBindingEnabled(true);
 
        CreateMenuBoxes();
 
        return this.mScene;
 
    }
 
    @Override
    public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
        this.mClickDetector.onTouchEvent(pSceneTouchEvent);
        this.mScrollDetector.onTouchEvent(pSceneTouchEvent);
        return true;
    }
 
    @Override
    public void onScroll(final ScrollDetector pScollDetector, final TouchEvent pTouchEvent, final float pDistanceX, final float pDistanceY) {
 
        //Disable the menu arrows left and right (15px padding)
        if(mCamera.getMinX()<=15)
           menuleft.setVisible(false);
         else
           menuleft.setVisible(true);
         
         if(mCamera.getMinX()>mMaxX-15)
           menuright.setVisible(false);
         else
           menuright.setVisible(true);
           
        //Return if ends are reached
        if ( ((mCurrentX - pDistanceX) < mMinX) ){         
          return;
        }else if((mCurrentX - pDistanceX) > mMaxX){
           
          return;
        }
         
        //Center camera to the current point
        this.mCamera.offsetCenter(-pDistanceX,0 );
        mCurrentX -= pDistanceX;
           
        
        //Set the scrollbar with the camera
        float tempX =mCamera.getCenterX()-CAMERA_WIDTH/2;
        // add the % part to the position
        tempX+= (tempX/(mMaxX+CAMERA_WIDTH))*CAMERA_WIDTH;  
        //set the position
        scrollBar.setPosition(tempX, scrollBar.getY());
         
        //set the arrows for left and right
        menuright.setPosition(mCamera.getCenterX()+CAMERA_WIDTH/2-menuright.getWidth(),menuright.getY());
        menuleft.setPosition(mCamera.getCenterX()-CAMERA_WIDTH/2,menuleft.getY());
         
        
         
        //Because Camera can have negativ X values, so set to 0
        if(this.mCamera.getMinX()<0){
          this.mCamera.offsetCenter(0,0 );
          mCurrentX=0;
        }
         
 
    }
 
    @Override
    public void onClick(ClickDetector pClickDetector, TouchEvent pTouchEvent) {
        loadLevel(iItemClicked);
    };
 
    // ===========================================================
    // Methods
    // ===========================================================
     
    private void CreateMenuBoxes() {
       
       int spriteX = PADDING;
       int spriteY = PADDING;
       
       //current item counter
       int iItem = 1;
 
       for (int x = 0; x < columns.size(); x++) {
         
         //On Touch, save the clicked item in case it's a click and not a scroll.
         final int itemToLoad = iItem;
         
         Sprite sprite = new Sprite(spriteX,spriteY,columns.get(x)){
           
           public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
             iItemClicked = itemToLoad;
             return false;
           }          
         };        
         iItem++;
         
         
         this.mScene.attachChild(sprite);        
         this.mScene.registerTouchArea(sprite);        
  
         spriteX += 20 + PADDING+sprite.getWidth();
      }
       
       mMaxX = spriteX - CAMERA_WIDTH;
       
       //set the size of the scrollbar
       float scrollbarsize = CAMERA_WIDTH/((mMaxX+CAMERA_WIDTH)/CAMERA_WIDTH);
       scrollBar = new Rectangle(0,CAMERA_HEIGHT-20,scrollbarsize, 20);
       scrollBar.setColor(1,0,0);
       this.mScene.attachChild(scrollBar);
       
       menuleft = new Sprite(0,CAMERA_HEIGHT/2-mMenuLeftTextureRegion.getHeight()/2,mMenuLeftTextureRegion);
       menuright = new Sprite(CAMERA_WIDTH-mMenuRightTextureRegion.getWidth(),CAMERA_HEIGHT/2-mMenuRightTextureRegion.getHeight()/2,mMenuRightTextureRegion);
       this.mScene.attachChild(menuright);
       menuleft.setVisible(false);
       this.mScene.attachChild(menuleft);
    }
     
     
 
    @Override
    public void onLoadComplete() {
 
    }
 
    //Here is where you call the item load.
    private void loadLevel(final int iLevel) {
        if (iLevel != -1) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                       
                    Toast.makeText(MenuScrollerActivity.this, "Load Item" + String.valueOf(iLevel), Toast.LENGTH_SHORT).show();
                    iItemClicked = -1;
                }
            });
        }
    }
}

以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日产一区二区 | 欧美高清在线不卡免费观看 | 亚洲国产在线综合018 | 午夜免费小视频 | 青青草国产精品久久久久 | 新影音先锋男人色资源网 | 国产小视频在线免费观看 | 色综合久久九月婷婷色综合 | 狠狠色婷婷狠狠狠亚洲综合 | 非洲黑人bbwbbwbbw | 欧美久久影院 | 国产福利视频一区二区微拍视频 | 秋霞理论在一l级毛片 | 欧美精品1区2区 | 亚洲精品无码久久不卡 | 国产精品国产精品国产三级普 | 天美影视文化传媒mv免费 | 日本高清视频一区二区 | 日本69视频在线观看 | 精品无人区乱码1区2区3区免费 | 国产综合亚洲专区在线 | 国产精品亚洲精品青青青 | 久久成人国产精品一区二区 | 精品一区二区三区自拍图片区 | 国产亚洲女在线精品 | 久久精麻豆亚洲AV国产品 | 国产精品自在欧美一区 | 亚洲精品视| 欧美日韩国产亚洲一区二区三区 | 国产麻豆网 | 黄动漫软件车车好快的车车 | 9丨精品国产高清自在线看 9久热这里只有精品免费 | 久草在线草a免费线看 | 亚洲酒色1314狠狠做 | 欧美视频在线播放观看免费福利资源 | 日韩一级欧美一级一级国产 | jzzjlzz亚洲乱熟在线播放 | 506070老熟肥妇bbwxx视频 500第一精品 | 久久伊人中文字幕有码 | 王淑兰与铁柱全文免费阅读 | 女教师的一级毛片 |