【问题标题】:Strange horizontal lines when adding components to container向容器添加组件时出现奇怪的水平线
【发布时间】:2016-02-28 11:42:23
【问题描述】:

在将代码中的一系列容器添加到 GUI 构建器中定义的容器时,屏幕宽度上会出现均匀间隔的水平线,与组件的任何边框无关。

这是我的代码:

public Container[] renderArticles(ArrayList<HashMap<String, Object>> articles){
        Container[] artArray = new Container[articles.size()];
        for (int i = 0; i < articles.size(); i++) {
            final HashMap<String, Object> art = articles.get(i);
            Container artCon = mStateMachine.createContainer(mStateMachine.res, "DocArticleItem");
            ActionListener listen = new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    mStateMachine.currentArticleId = (String) art.get("id");
                    mStateMachine.showForm("Article", null);
                }
            };
            Button artPic = mStateMachine.findArticlePic(artCon);
            artPic.addActionListener(listen);
            artPic.setIcon(mStateMachine.makeImageFromRaw((String)art.get("picture_data")));
            SpanButton caption = (SpanButton)mStateMachine.findArticleTitle(artCon);
            caption.setText((String) art.get("title"));
            caption.addActionListener(listen);
            artArray[i] = artCon;
        }
        return artArray;
    }

public Container[] renderTips(ArrayList<HashMap<String, Object>> tips){
        Container[] contArray = new Container[tips.size()];
        for (int i = 0; i < tips.size(); i++) {
            HashMap<String, Object> tip = tips.get(i);
            Container tipCont = mStateMachine.createContainer(mStateMachine.res, "DocTipItem");
            SpanLabel tipTitle = mStateMachine.findDocTipTitle(tipCont);
            tipTitle.setText((String)tip.get("title"));
            SpanLabel tipText = mStateMachine.findDocTipText(tipCont);
            tipText.setText((String)tip.get("info"));
            contArray[i] = tipCont;
        }

        // remove divider from last tip
        Container last = contArray[contArray.length - 1];
        Container line = (Container)last.getComponentAt(last.getComponentCount() - 1);
        last.removeComponent(line);

        return contArray;
    }

final HashMap<String, Object> map = mStateMachine.expertCardInfo;

// populate tips
if (map.containsKey("tips")){
    tipContainers = renderTips((ArrayList) map.get("tips"));
}else{
     f.removeComponent(mStateMachine.findExpertTipsHeader(f));
     f.removeComponent(mStateMachine.findExpertTipsContainer(f));
}

// populate articles
if (map.containsKey("articles")) {
    articleContainers = renderArticles((ArrayList)map.get("articles"));
} else {
    f.removeComponent(mStateMachine.findExpertArticlesHeader(f));
    f.removeComponent(mStateMachine.findExpertArticlesContainer(f));
}

StateMachine:

@Override
    protected void onDoctorDetails_ExpertTipsHeaderAction(Component c, ActionEvent event) {
        Container cnt = findExpertTipsContainer(c.getComponentForm());
        if(cnt.getComponentCount() > 0){
            cnt.removeAll();
        }else{
            for (int i = 0;i < expRenderer.tipContainers.length;i++){
                cnt.add(expRenderer.tipContainers[i]);
            }
            c.getComponentForm().scrollComponentToVisible(cnt);
        }

    }

tl;dr:这是Component.setHidden() 的手动实现,由于某种原因无法正常工作。我根据从服务器获得的数据创建了一堆Containers,将它们粘贴在一个数组中,当单击按钮显示它们时,我遍历数组并添加Containers(每个都是本质上是一个列表项)到父 Container

我们将不胜感激任何朝着正确方向的推动。

更新

UI 层次结构如下所示:

Form (BoxLayout Y)
  |
   - Container (FlowLayout)
  |
   - Container (TableLayout)
  |
   - Container (TableLayout)
  |
   - Button
  |
   - Label
  |
   - Button (populates following container)
  |
   - Container (BoxLayout Y - doesn't show lines)
  |
   - Button (populates following container)
  |
   - Container (BoxLayout Y - shows lines)
  |
   - Button (populates following container)
  |
   - Container (BoxLayout Y - shows lines)

最后三个容器都具有相同的 UIID,它源自 Container,仅修改边距。不同之处在于添加到它们的容器。在第一个中,我添加了一系列SpanButtons(并且这些行没有出现)。在另外两个中,我添加了一系列预先组装好的容器,里面有一些内容(并且出现了线条)。后一种情况下添加的容器具有以下样式属性:

cn1-derive: Container; margin: 0; border-bottom: thin solid gray

解决方案

我在我的 css 文件中定义的底部边框似乎导致了奇怪的线条。当我评论那条线时,它们消失了。它不是仅在定义它的容器底部呈现,而是在整个容器中呈现。我认为这是一个错误。

【问题讨论】:

  • 你能发布你在设计器和你使用的主题元素中看到的层次结构吗?看看主题本身确实有一些在层次结构中定义的背景类型。您还可以在模拟器的组件检查器中检查可视组件层次结构。

标签: layout codenameone


【解决方案1】:

检查 GUI Builder 以查看您的容器 UIID 没有背景图像样式以及您的表单。

【讨论】:

  • 不,两者都没有背景。
【解决方案2】:

我猜你看到的是上面代码中的“行”条目。 setHidden() 只是最小化了组件请求的空间,并没有真正隐藏它。使用setVisible(false) 真正隐藏组件。

【讨论】:

  • 我看到的线条没有使用setHidden()setVisible()setVisible() 相当于 HTML 中的 display:none,还是会占用空间?
  • 请看我的回答 - 这可能是 css 插件中的一个错误。
【解决方案3】:

我在代码中添加的容器上设置了border-bottom,并在css文件中定义。这似乎触发了一个错误,导致边框在整个容器中以均匀的间隔呈现,而不仅仅是在容器的底部。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 2018-09-17
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    相关资源
    最近更新 更多