有时候你需要自己定义basiceditfield的长宽等属性,这里就需要layout,下面实例为你介绍如何自定义。
package newpackage; import net.rim.device.api.system.Display; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.BasicEditField; import net.rim.device.api.ui.component.ButtonField; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.container.MainScreen; /** * * @author Tiandi Zhang */ public class Demo extends UiApplication { public static void main(String[] args){ Demo theApp = new Demo(); theApp.enterEventDispatcher(); } public Demo(){ pushScreen(new mainscreen()); } } class mainscreen extends MainScreen{ public mainscreen() { super(); LabelField title = new LabelField("TextField Demo",LabelField.ELLIPSIS|LabelField.USE_ALL_WIDTH); setTitle(title); BasicEditField t1 = new BasicEditField("Text",""){ public int getPreferredWidth() { return Display.getWidth(); } public int getPreferredHeight() { return 100; } public void layout(int width, int height) { super.layout(width, getPreferredHeight()); setExtent(width, getPreferredHeight()); } }; ButtonField b1 = new ButtonField("save"); add(t1); add(b1); } }
文章评分1次,平均分5.0:★★★★★
黑莓……好厉害
这是什么的代码啊?