Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 聊天窗口设计-黑莓_Blackberry - Fatal编程技术网

Blackberry 聊天窗口设计-黑莓

Blackberry 聊天窗口设计-黑莓,blackberry,Blackberry,我尝试实现一个聊天窗口(聊天功能运行良好且顺畅)。我在设计中下部时遇到了问题。在中间部分聊天信息中&底部,我想添加可编辑字段。若我固定了可编辑字段对齐底部聊天信息不显示,若我在底部后添加可编辑字段,则聊天信息显示在屏幕上。 我用过 我想在屏幕底部附加字段&消息显示在滚动条中间。在这里,我还附加了我在聊天时使用的伪消息(没有Json数据)代码。谢谢 package-mypackage; 导入net.rim.device.api.system.*; 导入net.rim.device.api.ui.*

我尝试实现一个
聊天窗口
(聊天功能运行良好且顺畅)。我在设计
中下部时遇到了问题。在
中间部分聊天信息中
&底部,我想添加可编辑字段。若我固定了可编辑字段对齐底部聊天信息不显示,若我在底部后添加可编辑字段,则聊天信息显示在屏幕上。 我用过

我想在屏幕底部附加字段&消息显示在滚动条中间。在这里,我还附加了我在聊天时使用的伪消息(没有Json数据)代码。谢谢

package-mypackage;
导入net.rim.device.api.system.*;
导入net.rim.device.api.ui.*;
导入net.rim.device.api.ui.component.*;
导入net.rim.device.api.ui.container.HorizontalFieldManager;
导入net.rim.device.api.ui.container.main屏幕;
导入net.rim.device.api.ui.container.VerticalFieldManager;
导入net.rim.device.api.ui.decor.*;
公共类聊天列表扩展主屏幕
{
Manager |前台=新的NegativeMarginVerticalFieldManager(使用|全部|宽度|全部|高度|垂直|滚动);
BasicEditField味精;
公共聊天列表(){
超级(无垂直滚动);
设置标题(“聊天”);
//设置线性背景。
此.getMainManager().setBackground(
BackgroundFactory.createLinearGradientBackground(0x91e7ff、0x0099CCFF、0x00336699、0x91e7ff)
);
//添加字段底部
HorizontalFieldManager hfm=新的HorizontalFieldManager(使用所有高度、使用所有宽度);
VerticalFieldManager vfm=新的VerticalFieldManager(使用所有宽度字段底部);
msg=新的BasicEditField();
msg.setboorder(BorderFactory.createRoundedBorder(新的XYEdge(3,3,3,3),0x99999,Border.STYLE_FILLED));
msg.setBackground(BackgroundFactory.createSolidBackground(0xE0));
msg.setPadding(5,0,5,0);
msg.setMargin(0,10,0,10);
添加(味精);
hfm.add(vfm);
添加(hfm);
}
公共布尔键关闭(整数键代码,整数时间){
if(Keypad.KEY_ENTER==Keypad.KEY(keycode)){
String message=msg.getText();
如果(!message.equals(“”)
{
Border rightBorder=BorderFactory.createBitmapBorder(新的XYEdge(16,23,27,16),Bitmap.getBitmapResource(“Border_bubble_right.png”);
Border leftBorder=BorderFactory.createBitmapBorder(新的XYEdge(16,16,27,23),Bitmap.getBitmapResource(“Border_bubble_left.png”);
addHeading(“Hello Adil!”,leftBorder,Field.Field_LEFT);
addHeading(“是的,我看到了”,右边框,Field.Field\u RIGHT);
addHeading(“有任何更新,与此相关??”,leftBorder,Field.Field_LEFT);
addHeading(“别担心,我会完成的”,rightBorder,Field.Field_RIGHT);
addHeading(“中间部分消息”,左边框,Field.Field_LEFT);
addHeading(“垂直滚动加载项消息”,左边框,Field.Field_左);
addHeading(“有任何更新!”,右边框,Field.Field\u RIGHT);
addHeading(“最好继续”,左边框,Field.Field\u LEFT);
addHeading(“别担心,我会完成的”,rightBorder,Field.Field_RIGHT);
addHeading(“底部对齐基本可编辑字段?”,左边框,Field.Field_LEFT);
添加标题(“可能”,右边框,Field.Field_RIGHT);
addHeading(“最好继续”,左边框,Field.Field\u LEFT);
addHeading(“别担心,我会完成的”,rightBorder,Field.Field_RIGHT);
msg.setText(“”);
//添加所有字段
添加(_前台);
}//如果条件
else{Dialog.alert(“请插入消息”);}
返回true;
}
//让系统将事件传递给另一个侦听器。
返回false;
}
私有void addHeading(字符串标签、边框、长样式)
{
LabelField标头=新LabelField(标签,Field.FOCUSABLE |样式);
表头.订单(边框);
标题.设置边距(5,5,-15,5);
_前台添加(表头);
}   
}
试试这个-(我稍微修改了你的代码。)

JustifiedHorizontalFieldManager.java如下所示-

public class JustifiedHorizontalFieldManager extends Manager
{
    private static final int SYSTEM_STYLE_SHIFT = 32;

    public Field _leftField;
    public Field _rightField;

    private boolean _giveLeftFieldPriority;

    public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
    {
    this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}

public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
    super( style );

    _leftField = leftField;
    _rightField = rightField;

    add( _leftField );
    add( _rightField );

    _giveLeftFieldPriority = giveLeftFieldPriority;
}


public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
    super( style ); 
    _giveLeftFieldPriority = giveLeftFieldPriority;
}

public void addLeftField( Field field )
{
    if( _leftField != null ) {
        throw new IllegalStateException();
    }
    _leftField = field;
    add( _leftField );
}

public void addRightField( Field field )
{
    if( _rightField != null ) {
        throw new IllegalStateException();
    }
    _rightField = field;
    add( _rightField );
}

public int getPreferredWidth()
{
    return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}

public int getPreferredHeight()
{
    return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}

protected void sublayout( int width, int height )
{
    Field firstField;
    Field secondField;
    if( _giveLeftFieldPriority ) {
        firstField = _leftField;
        secondField = _rightField;
    } else {
        firstField = _rightField;
        secondField = _leftField;
    }

    int maxHeight = 0;

    int availableWidth = width;
    availableWidth -= _leftField.getMarginLeft();
    availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
    availableWidth -= _rightField.getMarginRight();

    layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
    maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
    availableWidth -= firstField.getWidth();

    layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
    maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
    availableWidth -= secondField.getWidth();

    if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
        height = maxHeight;
    }
    if( !isStyle( Field.USE_ALL_WIDTH ) ) {
        width -= availableWidth;
    }

    setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
    setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );

    setExtent( width, height );
}

private int getFieldY( Field field, int height )
{
    switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
        case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
            return height - field.getHeight() - field.getMarginBottom();
        case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
            return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
        default:
            return field.getMarginTop();
    }
}


public Field getLeftField()
{
    return _leftField;
}

public Field getRightField()
{
    return _rightField;
}

public void replace( Field oldField, Field newField )
{
    if( oldField == newField ) {
        // Nothing to do
        return;
    }

    if( oldField == _leftField ) {
        _leftField = newField;
    } else if( oldField == _rightField ) {
        _rightField = newField;
    }
    add( newField );
    delete( oldField );
}



}    

谢谢@signare!但在中间部分,信息不显示在屏幕上??信息正在显示。只需单击发送按钮,就会显示消息。谢谢@Signare!它在设备上运行良好,首先我在模拟器上检查它。
public class JustifiedHorizontalFieldManager extends Manager
{
    private static final int SYSTEM_STYLE_SHIFT = 32;

    public Field _leftField;
    public Field _rightField;

    private boolean _giveLeftFieldPriority;

    public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
    {
    this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}

public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
    super( style );

    _leftField = leftField;
    _rightField = rightField;

    add( _leftField );
    add( _rightField );

    _giveLeftFieldPriority = giveLeftFieldPriority;
}


public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
    super( style ); 
    _giveLeftFieldPriority = giveLeftFieldPriority;
}

public void addLeftField( Field field )
{
    if( _leftField != null ) {
        throw new IllegalStateException();
    }
    _leftField = field;
    add( _leftField );
}

public void addRightField( Field field )
{
    if( _rightField != null ) {
        throw new IllegalStateException();
    }
    _rightField = field;
    add( _rightField );
}

public int getPreferredWidth()
{
    return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}

public int getPreferredHeight()
{
    return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}

protected void sublayout( int width, int height )
{
    Field firstField;
    Field secondField;
    if( _giveLeftFieldPriority ) {
        firstField = _leftField;
        secondField = _rightField;
    } else {
        firstField = _rightField;
        secondField = _leftField;
    }

    int maxHeight = 0;

    int availableWidth = width;
    availableWidth -= _leftField.getMarginLeft();
    availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
    availableWidth -= _rightField.getMarginRight();

    layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
    maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
    availableWidth -= firstField.getWidth();

    layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
    maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
    availableWidth -= secondField.getWidth();

    if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
        height = maxHeight;
    }
    if( !isStyle( Field.USE_ALL_WIDTH ) ) {
        width -= availableWidth;
    }

    setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
    setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );

    setExtent( width, height );
}

private int getFieldY( Field field, int height )
{
    switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
        case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
            return height - field.getHeight() - field.getMarginBottom();
        case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
            return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
        default:
            return field.getMarginTop();
    }
}


public Field getLeftField()
{
    return _leftField;
}

public Field getRightField()
{
    return _rightField;
}

public void replace( Field oldField, Field newField )
{
    if( oldField == newField ) {
        // Nothing to do
        return;
    }

    if( oldField == _leftField ) {
        _leftField = newField;
    } else if( oldField == _rightField ) {
        _rightField = newField;
    }
    add( newField );
    delete( oldField );
}



}