TextPaint texto = new TextPaint();
StaticLayout layout = new StaticLayout("My long long long long text! My long long long long text! .", texto, 140,android.text.Layout.Alignment.ALIGN_CENTER,(float)1.0, (float)0.0, true);
layout.draw(canvas);
Android, Blackberry and Corona SDK tutorials.
CustomLabel
package com.ui;
import net.rim.device.api.ui.Font;import net.rim.device.api.ui.Graphics;import net.rim.device.api.ui.Manager;import net.rim.device.api.ui.XYEdges;import net.rim.device.api.ui.component.EditField;import net.rim.device.api.ui.component.LabelField;import net.rim.device.api.ui.container.VerticalFieldManager;import net.rim.device.api.ui.decor.BackgroundFactory;import net.rim.device.api.ui.decor.Border;import net.rim.device.api.ui.decor.BorderFactory;
public class CustomLabel{//You can change this colors as you like!private int titleFontColor = 0x2bb7de;private int textFontColor=0x000000;private int bgColor = 0xe8e8e8;private VerticalFieldManager vm;private LabelField titleLabel;private EditField textField;private Font _font;private int _labelHeight;private int _labelWidth;
public CustomLabel(String title, String text){//We create a Vertical Field Manager that will wrap all our contentvm = new VerticalFieldManager(Manager.USE_ALL_WIDTH);//Now we set our border style to simulate a cool efectXYEdges padding = new XYEdges(15, 15, 15, 15);vm.setBorder(BorderFactory.createRoundedBorder(padding, bgColor, Border.STYLE_FILLED));//We set the same Background color to the border and to our//Manager Background so it looks all the same fieldvm.setBackground(BackgroundFactory.createSolidBackground(bgColor));//We create our title LabelField and set the same background colortitleLabel = new LabelField(""){public void paint(Graphics g){g.setColor(titleFontColor);super.paint(g);}};titleLabel.setText(title);//Our text LabelField again with the same background colortextField = new EditField("","", bgColor, EditField.READONLY){public void paint(Graphics g){g.setColor(textFontColor);super.paint(g);}};textField.setText(text);//Now we set some padding and add our elements to our CustomField!vm.setPadding(5, 5, 5, 5);vm.add(titleLabel);vm.add(textField);_labelHeight = textField.getHeight()+titleLabel.getHeight();_labelWidth = textField.getWidth()+titleLabel.getWidth();}public VerticalFieldManager getField(){return vm;}}