Codenameone textArea growByContent在图层布局中不起作用

Codenameone textArea growByContent在图层布局中不起作用,codenameone,Codenameone,我使用图层布局将标题ie文本区域保留在按钮图像的顶部。但我不能增加文本区域的大小。此外,文本区域上的填充和边距也不起作用 Image btnIcon = URLImage.createToStorage(placeholder, "homeIcon" + imageUrl, allUrl.globalHomeImageUrl + imageUrl, URLImage.RESIZE_SCALE); int width = placeholder.ge

我使用图层布局将标题ie文本区域保留在按钮图像的顶部。但我不能增加文本区域的大小。此外,文本区域上的填充和边距也不起作用

            Image btnIcon = URLImage.createToStorage(placeholder, "homeIcon" + imageUrl, allUrl.globalHomeImageUrl + imageUrl, URLImage.RESIZE_SCALE);
            int width = placeholder.getWidth();
            int height = placeholder.getHeight();
            homeButton.setPreferredSize(new Dimension(width, height));
            homeButton.getAllStyles().setBgImage(btnIcon);

            TextArea buttonTitle = new TextArea(title);
            buttonTitle.setRows(1);
            buttonTitle.setUIID("smallLabel");
            buttonTitle.getAllStyles().setPadding(0, 0, 0, 0);
            buttonTitle.getAllStyles().setMargin(0, 4, 0, 4);
            buttonTitle.setPreferredW(screenWidth / 3 - 30);
            buttonTitle.setEditable(false);
            buttonTitle.setGrowByContent(true);
            buttonTitle.setIsScrollVisible(false);
            buttonTitle.setGrowLimit(2);
            Container container1 = new Container();
            container1.setUIID("buttonTitleContainer");
            container1.getAllStyles().setMargin(0, 5, 0, 0);
            container1.getAllStyles().setBgTransparency(0);
            container1.add(LayeredLayout.encloseIn(homeButton,     FlowLayout.encloseRightBottom(buttonTitle)));
            middleContainer.addComponent(BorderLayout.CENTER, container1);
如何根据需要增长textArea行并设置textArea的填充边距

更新: 我注释了setPreferredW()并添加了calcPreferredSize()来设置尺寸,但如何动态设置高度

TextArea buttonTitle = new TextArea(title){

                        @Override
                        protected Dimension calcPreferredSize() {
                            Dimension d = new Dimension(screenWidth/3-10, 40);
                            return d; //To change body of generated methods, choose Tools | Templates.
                        }

                    };
                    buttonTitle.setUIID("smallLabel");
                    buttonTitle.getAllStyles().setAlignment(Label.LEFT);
                    buttonTitle.setRows(1);
                    buttonTitle.getAllStyles().setPadding(0, 0, 0, 0);
                    buttonTitle.getAllStyles().setMargin(0, 0, 0, 4);
//                    buttonTitle.setPreferredW(screenWidth / 3 - 30);
                    buttonTitle.setEditable(false);
                    buttonTitle.setGrowByContent(true);
                    buttonTitle.setIsScrollVisible(false);
                    buttonTitle.setGrowLimit(2);
                    buttonTitle.setScrollVisible(false);
设计如下:

当前屏幕截图: 如您所见,只显示一个单词,文本区域始终只有一行,并且不会增长


问题不在
分层布局中,而是因为您调用了弃用的
setPreferredW


请注意,
setPreferredW
也限制了高度。

问题不在
LayeredLayout
中,而是因为您调用了弃用的
setPreferredW


请注意,
setPreferredW
也限制了高度。

谢谢,我删除了setPreferredW并使用了calcPreferredSize,但我无法使其正常工作。我已经更新了上面的问题。请看一看。谢谢我不明白集装箱1的目标是什么?它是一个
FlowLayout
容器,似乎可以包装东西?container1被设置为gridlayout,它添加了若干层布局的组件,以将textArea放置在按钮的右下角。我已经上传了我想要实现的设计上面。看一看。你删除了你现在拥有的图像,所以它没有真正的帮助,因为我不知道你做错了什么。如果您使用的网格布局没有在流布局中封装内容,那么您不需要首选大小,因为网格布局将接管整个单元大小,就像在设计中一样。您可以按照自己的意愿确定行/列:实际上,我在按钮中使用了setBgImage,因此btn不会显示bg图像,除非我设置了大小。抱歉,前一个img被意外删除,我再次更新了当前img。谢谢,我删除了setPreferredW并使用calcPreferredSize,但我无法使其正常运行。我已经更新了上面的问题。请看一看。谢谢我不明白集装箱1的目标是什么?它是一个
FlowLayout
容器,似乎可以包装东西?container1被设置为gridlayout,它添加了若干层布局的组件,以将textArea放置在按钮的右下角。我已经上传了我想要实现的设计上面。看一看。你删除了你现在拥有的图像,所以它没有真正的帮助,因为我不知道你做错了什么。如果您使用的网格布局没有在流布局中封装内容,那么您不需要首选大小,因为网格布局将接管整个单元大小,就像在设计中一样。您可以按照自己的意愿确定行/列:实际上,我在按钮中使用了setBgImage,因此btn不会显示bg图像,除非我设置了大小。对不起,以前的img被意外删除了,我再次更新了当前的img。