我正在开发和使用应用程序,但聊天气泡不合适。我正在使用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;
}
}
答案 0 :(得分:1)
为防止箭头伸展,它必须位于9补丁图像的一个角落内。