如何在代号one中使所有可滑动容器具有相同的高度?

How to make all swipable container with the same height in codenameone?

我正在尝试显示与容器一起提交且高度相同且容器包含 texts/images 的行。我正在为此显示 table 列表。

见下图。

我想显示相同高度的行。

下面是我用过的代码。我将 Swipable 容器用作 table 行。

tableContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
tableContainer.setUIID("transparent");

//Table Header - Start
Container tableHeaderRowContainer = new Container();
tableHeaderRowContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));
tableHeaderRowContainer.setScrollable(false);
tableHeaderRowContainer.setUIID("TableHeaderBg");

Container tableHeaderContainer = new Container(new TableLayout(1,columnNames.length));
tableHeaderContainer.setScrollable(false);
tableHeaderContainer.setUIID("TableHeaderBg");

for(int col=0;col<columnNames.length;col++){
  final String colName = columnNames[col];
  Container headerContainer = new Container();
  headerContainer.setUIID("TableHeaderBg");
  Button headerButton = new Button();

  SpanLabel headerTitle = new SpanLabel(colName);
  headerTitle.setTextUIID("TableHeader");
  headerTitle.setUIID("TableHeader");
  headerContainer.addComponent(headerTitle);
  headerContainer.setFocusable(false);
  headerContainer.setLeadComponent(headerButton);
  headerButton.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent evt) {

    }
 });
 // tableHeaderContainer.add(l1);
 TableLayout.Constraint constraint = ((TableLayout)tableHeaderContainer.getLayout()).createConstraint();
 constraint = ComponentUtils.setTableConstraint(constraint, col); 
 tableHeaderContainer.addComponent(constraint,headerContainer);

} 

selectAllCheckBox = new CheckBox();
selectAllCheckBox.setUIID("TableHeaderCheck");
tableHeaderRowContainer.addComponent(selectAllCheckBox);
tableHeaderRowContainer.addComponent(tableHeaderContainer);
tableContainer.addComponent(tableHeaderRowContainer);
//Table Header - End

//Table list - start
Container tableContainerMain = new Container();
tableContainerMain.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
tableContainerMain.setScrollableY(true);

for(int row=0;row<data.length;row++){
   String jobReference = jobRefList[row];

   Container tableRowContainer = new Container();
   tableRowContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));
   tableRowContainer.setScrollable(false);

   Button actionButton = new Button();
   final Container rowContainer = new Container(new TableLayout(1,columnNames.length));

   if(row%2==0){
       rowContainer.setUIID("even");
       tableRowContainer.setUIID("evenPadding");
   }
   else{
       rowContainer.setUIID("odd");
       tableRowContainer.setUIID("oddPadding");
   }

   rowContainer.setFocusable(false);
   rowContainer.setLeadComponent(actionButton);

   JobDataDetail jobRef = editJobs[row];
   final JobData jobDataRef = Utility.getJobDataWithStatus(jobData);
   jobDataRef.setJobDataDetail(jobRef);

   for(int col=0;col<columnNames.length;col++){
         Label statusLabel = new Label();
         String imageName = "";
         if(data[row][col]!=null && (data[row][col].toString().equalsIgnoreCase(Constants.STATUS_ACTIVE) 
                 || data[row][col].toString().equalsIgnoreCase(Constants.STATUS_REACTIVE))){ 
             imageName = "st-completed.png";
         }
         else if(data[row][col].toString().equalsIgnoreCase(Constants.STATUS_ACTIVE_NONCOMPLETE)){ 
             imageName = "st-incomplete.png";
         }
         else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_PENDING) ){
             imageName = "st-pending.png";
         }
         else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_SYNCED) ){
             imageName = "st-synched.png";
         }
         else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_CHECKIN) ){
             imageName = "st-checkedin.png";
         }
         else if(data[row][col]!=null && data[row][col].toString().equalsIgnoreCase(Constants.STATUS_CLOSED) ){
             imageName = "st-closed.png";
         }

         if(!Utility.isBlankOrNull(imageName)){
              statusLabel = new Label(res.getImage(imageName));
              if(row%2==0){
                  statusLabel.setUIID("evenImageLabel");
           }
           else{
               statusLabel.setUIID("oddImageLabel");
           }
              statusLabel.setVerticalAlignment(Label.TOP);
              Container labelContainer = new Container();
           if(row%2==0){
               labelContainer.setUIID("even");
           }
           else{
               labelContainer.setUIID("odd");
           }
           labelContainer.addComponent(FlowLayout.encloseIn(statusLabel));
               TableLayout.Constraint constraint1 = ((TableLayout) rowContainer.getLayout()).createConstraint();
               constraint1 = ComponentUtils.setTableConstraint(constraint1, col);
               rowContainer.addComponent(constraint1, labelContainer);

          }
          else{
             /*
              SpanLabel txtLabel = new SpanLabel((String) data[row][col]);
              txtLabel.setTextUIID("login_title");
              txtLabel.setUIID("transparent");*/

              TextArea txtLabel = new TextArea((String) data[row][col]);
              txtLabel.setUIID("login_title");
              txtLabel.setEditable(false);
              txtLabel.setRows(2);
              txtLabel.setScrollVisible(false);


              TableLayout.Constraint constraint1 = ((TableLayout) rowContainer.getLayout()).createConstraint();
              constraint1 = ComponentUtils.setTableConstraint(constraint1, col);
              rowContainer.addComponent(constraint1, txtLabel);

          }

   SwipeableContainer swipeableContainer = new SwipeableContainer(null,actionButtons[row], rowContainer);
   swipeableContainer.setUIID("transparent");
   swipeableContainer.setSmoothScrolling(true);
   swipeableContainer.setSwipeActivated(true);
   Container checkContainer = new Container();
   if(row%2==0){
       checkContainer.setUIID("even");
   }
   else{
       checkContainer.setUIID("odd");
   }
   CheckBox c = new CheckBox();
   c.setName(jobReference);
       if(row%2==0){
       c.setUIID("evenCheck");
   }
   else{
       c.setUIID("oddCheck");
   }
   c.setVerticalAlignment(TOP);
   checkBoxArr.add(c);
   checkContainer.addComponent(FlowLayout.encloseIn(c));
   tableRowContainer.addComponent(checkContainer);
   tableRowContainer.addComponent(swipeableContainer);
   tableContainerMain.addComponent(tableRowContainer);
}
}

tableContainer.addComponent(tableContainerMain);
//Table list - End

addComponent(BorderLayout.CENTER, tableContainer);

已编辑:

我已经应用了 diamond 给出的解决方案,但似乎仍然没有解决。

请看图中,第三条线达到给定高度。

TextArea 设计为根据其内容的大小增长,您可以对其添加限制:

TextArea txtLabel = new TextArea((String) data[row][col]);
txtLabel.setUIID("login_title");
txtLabel.setEditable(false);
txtLabel.setRows(2);
txtLabel.setGrowLimit(2);
txtLabel.setScrollVisible(false);