开发者

Button position in android

开发者 https://www.devze.com 2023-01-10 19:08 出处:网络
I\'m trying to make some "Chat view" with speech bubbles like on the SMS iPhone app. This is a row I have done in the xml editor :

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

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

But when I launch 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 from 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 alignment parent right and top to true but it doesn't work. Another problem: if I want to change the background of my button, this one disappears!

Thanks for 开发者_JAVA百科your help!!


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消