【发布时间】: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