Alternate Chat Bubble Widths
I am developing a chat type application. I am using two different nine patches for chat bubble main message and responses. The problem I am facing is to automatically wrapping the
Solution 1:
When I first posted this question, I just started Android programming. The problem was I overly complicated my layout definitions and code. Now that I simplified my layout hierarchy, I have achieved what I wanted and without using any layout weight and with a lot simple code/configuration. Here I am posting my updated code snippets.
My Main layout now:
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="wrap_content"android:layout_height="fill_parent"><ListViewandroid:id="@+id/list"android:layout_width="fill_parent"android:layout_height="0dip"android:layout_weight="1"android:stackFromBottom="true"android:transcriptMode="alwaysScroll"android:cacheColorHint="#00000000"android:listSelector="@android:color/transparent"android:divider="@null"/><LinearLayoutandroid:id="@+id/footer"android:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:gravity="bottom"style="@android:style/ButtonBar"><Buttonandroid:id="@+id/stt_button"android:layout_width="45dp"android:layout_height="50dp"android:background="@drawable/microphone"/><EditTextandroid:id="@+id/chat_msg"android:inputType="text"android:layout_width="0dp"android:layout_height="40dp"android:layout_weight="1" /><Buttonandroid:id="@+id/send_button"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_gravity="center_vertical"android:text="@string/send_button" /></LinearLayout></LinearLayout>
List item layout:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:weightSum="1.0"android:layout_weight="1"android:layout_height="wrap_content"><TextViewandroid:id="@+id/lefttext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dip"android:layout_marginRight="10dip"android:layout_marginTop="10dip"android:layout_marginBottom="5dip"android:layout_alignParentLeft="true"android:maxWidth="250dip"/><TextViewandroid:id="@+id/righttext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dip"android:layout_marginRight="10dip"android:layout_marginTop="10dip"android:layout_marginBottom="5dip"android:layout_alignParentRight="true"android:maxWidth="250dip"/></RelativeLayout>
This is the code inside the getView method of my custom array adapter:
Viewview= convertView;
if(view == null){
view = mInflater.inflate(R.layout.list_item, null);
}
Resourcesres= getContext().getResources();
DrawablebubblesChat= res.getDrawable(R.drawable.bubbles_chat);
DrawablebubblesResponse= res.getDrawable(R.drawable.bubbles_response);
TextViewleft= (TextView) view.findViewById(R.id.lefttext);
TextViewright= (TextView) view.findViewById(R.id.righttext);
Stringtxt=super.getItem(position);
if(txt.startsWith("s:")) {
left.setText(getItem(position));
left.setBackgroundDrawable(bubblesChat);
right.setText("");
right.setBackgroundDrawable(null);
} else {
right.setText(getItem(position));
right.setBackgroundDrawable(bubblesResponse);
left.setText("");
left.setBackgroundDrawable(null);
}
return view;
Post a Comment for "Alternate Chat Bubble Widths"