views:

373

answers:

1

Hello, I'm trying to make some "Chat view" with speech bubbles like on the sms iPhone app. This is a row I done in the xml editor :

http://img44.imageshack.us/i/xml.png/

But when I launch the my application, I get this :

http://img59.imageshack.us/i/resultt.png/

I don't know why the button to answer is so far away my Relative layout border! This is the xml code of the speech bubble:

 <?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>

And this is the adapter getView() method (pseudo = nickname):

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;
}

As you can see, I set the layout alignement parent right and top to true but it doesn't works. Other problem : if i want to change the background of my button, this one disappear!

Thanks for your help (and sorry for my english)!

A: 

Looks like you set a margin to go around the entire button. Try doing just a margin for the top and none for the right. Also I could be wrong but isn't sp just for text and dp is for widths and whatnot?

Go from

android:layout_margin="8sp"

to

android:layout_marginTop="8sp"
Mike
I ever tried this but that don't work...
Anthony M.
It looks like for some reason the end of the layout or view pane, whatever you want to call it, ends before the message bubble ends on the right. Is this view a child of another view? It seems like it could be bigger.
Mike
Yes, I use this into a ListView, and this speech bublle is for the list rows.
Anthony M.
I think whats happening is that you are on the top right of the relative layout you posted here but the space given by the list view isn't as much as it should be. What I mean by that is that the list view is telling the relative view that it can only go so far over to the right. You should see if you can give the relative view more space.
Mike
Ok you gave me an idea, I replaced all the margins by paddings (so I had to set paddings on the root relative layout and remove margins from the button, image, ..) and that works fine!and for the problem of the button background, I probably made a mistake on the destination folder when I create my xml layout, it might not be in"Drawable" folder, I will try others.Thank you Mike!
Anthony M.