1

我正在开发和信使应用程序,但聊天气泡不正确。我正在使用 9-patch .png 图片。箭头也随着文本区域被拉伸。任何人都可以帮忙。

public class AwesomeAdapter extends BaseAdapter{
    private Context mContext;
    private ArrayList<Message> mMessages;



    public AwesomeAdapter(Context context, ArrayList<Message> messages) {
        super();
        this.mContext = context;
        this.mMessages = messages;
    }
    @Override
    public int getCount() {
        return mMessages.size();
    }
    @Override
    public Object getItem(int position) {       
        return mMessages.get(position);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Message message = (Message) this.getItem(position);

        ViewHolder holder; 
        if(convertView == null)
        {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.sms_row, parent, false);
            holder.message = (TextView) convertView.findViewById(R.id.message_text);
            convertView.setTag(holder);
        }
        else
            holder = (ViewHolder) convertView.getTag();

        holder.message.setText(message.getMessage());

        LayoutParams lp = (LayoutParams) holder.message.getLayoutParams();
        if(message.isStatusMessage())
        {
            holder.message.setBackgroundDrawable(null);
            lp.gravity = Gravity.CENTER;
            holder.message.setTextColor(mContext.getResources().getColor(R.color.textFieldColor));
        }
        else
        {       
            if(message.isMine())
            {
                holder.message.setBackgroundResource(R.drawable.chat_bg2);
                lp.gravity = Gravity.RIGHT;
            }
            else
            {
                holder.message.setBackgroundResource(R.drawable.chat_bg1);
                lp.gravity = Gravity.LEFT;
            }
            holder.message.setLayoutParams(lp);
            holder.message.setTextColor(mContext.getResources().getColor(R.color.textColor));   
        }
        return convertView;
    }
    private static class ViewHolder
    {
        TextView message;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

}

我的应用聊天气泡是这样的

这是我的形象

4

1 回答 1

1

为了防止箭头被拉伸,它必须在 9-patch 图像的一个角落内。9 补丁对话框

于 2013-10-01T07:29:00.470 回答