BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-23-2010, 04:42 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Sep 2010
Model: bold
PIN: N/A
Carrier: tmobile
Posts: 16
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default Having the hardest time understanding aligning of fields?

Please Login to Remove!

I am having some challenges aligning fields. I have tried using custom layout managers and just am not having a consistent layout where fields are aligned properly. I have written the following layout manager and even though it aligns items in left column properly, it fails on right column.

Code:
/*

 * GridFieldManager.java

 *

 *  <your company here>, <year>

 * Confidential and proprietary.

 */

package com.wastemanagement.containerpickup;

import net.rim.device.api.ui.Manager;

import net.rim.device.api.ui.Field;


/**

 *

 */

public class GridFieldManager extends Manager {

    private int numColumns;

   

    public GridFieldManager(int numColumns, long style) {   

    super(style);

    this.numColumns = numColumns;

    }

   

   

    protected void sublayout(int width, int height){

        int [] columnWidths = new int[numColumns];

        int availableWidth = width;

        int availableHeight = height;

       

        //for each column size allthe fields and get the maximum width

        for(int column = 0; column<numColumns; column++){

           

            for(int fieldIndex = column; fieldIndex < getFieldCount(); fieldIndex+=numColumns){

               

                Field field = getField(fieldIndex);

                layoutChild(field, availableWidth, availableHeight);

                if(field.getWidth()>columnWidths[column]){

                    columnWidths[column] = field.getWidth();

                }

               

            }

           

            availableWidth -= columnWidths[column];

           

        }

       

        int currentRow = 0;

        int currentRowHeight = 0;

        int rowYOffset = 0;

       

       

        //set the position of each field

       

        for(int fieldIndex = 0; fieldIndex < getFieldCount(); fieldIndex++)

        {

         Field field = getField(fieldIndex);

        

        

         int fieldOffset = 0;

        

         if ((field.getStyle() & Field.FIELD_RIGHT) ==Field.FIELD_RIGHT){

             fieldOffset = columnWidths[fieldIndex % numColumns] - field.getWidth();

            }

            if (fieldIndex % numColumns ==0){

             setPositionChild(field,0 + fieldOffset,rowYOffset);  

               

            }

            else{

            

             setPositionChild(field,columnWidths[(fieldIndex % numColumns)-1]+fieldOffset,rowYOffset);  

            }

           

           

            if (field.getHeight()> currentRowHeight){

               

                currentRowHeight = field.getHeight();

            }

           

           

            if (fieldIndex % numColumns == numColumns -1)

            {

                currentRow ++;

                rowYOffset+=currentRowHeight;

                currentRowHeight = 0;

               

               

               

                }

        }

       

       

       

       

        int totalWidth = 0;

        for (int i = 0; i < numColumns;i++){

           

            totalWidth += columnWidths[i];

        }

       

        setExtent(totalWidth, rowYOffset + currentRowHeight);

       

       

       

       

    }

   

}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

High voltage Flayback Transformer TBC-110PC15
$10.0
High voltage Flayback Transformer TBC-110PC15 pictureBussmann 5.5ABWNA2E 2EA 5.5KV CL High Voltage H.R.C. Fuse New
$60.0
Bussmann 5.5ABWNA2E 2EA 5.5KV CL High Voltage H.R.C. Fuse New pictureBUSSMANN PON20 Low Voltage Fuse,20A,PON,250VAC
$6.58
BUSSMANN PON20 Low Voltage Fuse,20A,PON,250VAC picture12/24V Digital LED Panel Voltmeter Voltage Meter Display Red For Motorcycle
$4.53
12/24V Digital LED Panel Voltmeter Voltage Meter Display Red For Motorcycle picture2Sets Green LED Panel Digital Voltage Display Voltmeter for Car Boat ATV UTV
$12.77
2Sets Green LED Panel Digital Voltage Display Voltmeter for Car Boat ATV UTV picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.