我正在尝试使用短信 iPhone 应用程序上的气泡制作一些“聊天视图”。这是我在 xml 编辑器中完成的一行:
http://img44.imageshack.us/i/xml.png/
但是当我启动我的应用程序时,我得到了这个:
http://img59.imageshack.us/i/resultt.png/
我不知道为什么要回答的按钮离我的Relative布局边框那么远!这是语音气泡的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:background="@drawable/bulle_chat"
android:layout_width="fill_parent">
<ImageView android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_height="40sp"
android:layout_width="40sp"
android:id="@+id/ImageViewPhoto"
android:scaleType="fitXY"
android:layout_margin="8sp"
android:src="@drawable/lady">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ImageViewPhoto"
android:layout_alignTop="@+id/ImageViewPhoto"
android:id="@+id/TextViewPseudo"
android:text="Pseudo"
android:textColor="#242424"
android:textStyle="bold">
</TextView>
<TextView android:layout_below="@id/TextViewPseudo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TextViewDate"
android:text="Date"
android:layout_toRightOf="@+id/ImageViewPhoto">
</TextView>
<Button android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:id="@+id/ButtonAnswer"
android:layout_height="40sp"
android:layout_width="40sp"
android:layout_margin="8sp">
</Button>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ImageViewPhoto"
android:layout_alignLeft="@+id/ImageViewPhoto"
android:textColor="#000000"
android:text="BlbalblablbalbalbalbalbalablabalbalablaballabalbBlbalblablbalbalbalbalbalablabalbalablaballabalbalbalaBlbalblablbalbalbalbalbalablabalbalablaballabalbalbalablablaalbalabla"
android:id="@+id/TextViewMessage"
android:layout_alignRight="@+id/ButtonAnswer"
android:paddingBottom="15sp">
</TextView>
</RelativeLayout>
这是适配器 getView() 方法(伪 = 昵称):
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = ctx.getLayoutInflater();
View v = inflater.inflate(R.layout.chat_row, null);
TextView pseudo = (TextView)v.findViewById(R.id.TextViewPseudo);
TextView date = (TextView)v.findViewById(R.id.TextViewDate);
TextView message = (TextView)v.findViewById(R.id.TextViewMessage);
ImageView icon = (ImageView)v.findViewById(R.id.ImageViewPhoto);
Button b = (Button)v.findViewById(R.id.ButtonAnswer);
b.setId(position);
b.setOnClickListener((OnClickListener) ctx);
pseudo.setText(listMessages.get(position).getPseudo());
pseudo.setTextColor(0xFF000000);
date.setText(listMessages.get(position).getDate());
date.setTextColor(0xFF000000);
message.setText(listMessages.get(position).getText());
message.setTextColor(0xFF000000);
message.setGravity(Gravity.CLIP_HORIZONTAL);
if (listMessages.get(position).getThumb()!=null){
icon.setImageBitmap(listMessages.get(position).getThumb());
} else {
icon.setImageResource(R.drawable.unknown);
}
return v;
}
如您所见,我将布局对齐父级右侧和顶部设置为 true,但它不起作用。其他问题:如果我想改变按钮的背景,这个就消失了!
感谢您的帮助(对不起我的英语)!