ListLayout.java
上传用户:luxiaowei
上传日期:2022-06-06
资源大小:58k
文件大小:1k
源码类别:

J2ME

开发平台:

Java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package com.framework;
  6. import javax.microedition.lcdui.Graphics;
  7. /**
  8.  *
  9.  * @author swaroop_kumar
  10.  */
  11. public class ListLayout implements Layout{
  12.     int startX,startY,padding,horAllignment;
  13.     public ListLayout(int startX, int startY, int padding, int horAllignment) {
  14.         this.startX = startX;
  15.         this.startY = startY;
  16.         this.padding = padding;
  17.         this.horAllignment = horAllignment;
  18.     }
  19.     
  20.     
  21.     public void applyLayout(ScrollableContainer container) {
  22.         int _y = startY;
  23.         int containerWidth = container.getWidth() ;
  24.         if(container.isScrollBarPresent())
  25.         {
  26.             containerWidth -= ScrollableContainer.SCROLL_BAR_WIDTH;
  27.         }
  28.         for (int i = 0; i < container.childrens.size(); i++) {
  29.             UIControl control = (UIControl)container.childrens.elementAt(i);
  30.             int x = startX;
  31.             if(horAllignment == Graphics.HCENTER)
  32.             {
  33.                 if(control.getWidth() > containerWidth)
  34.                 {
  35.                     control.setWidth(containerWidth);
  36.                 }
  37.                 x = (containerWidth - control.getWidth()) >> 1;
  38.             }else if(horAllignment == Graphics.RIGHT)
  39.             {
  40.                 x = container.getWidth() - control.getWidth() - startX;
  41.             }
  42.             control.setPoistion(x, _y);
  43.             _y += control.getHeight() + padding;
  44.         }
  45.     }
  46. }