<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/even_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.20" >
<com.lociiapp.utils.RoundedImageView
android:id="@+id/odd_bubble"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_margin="5dip"
android:visibility="visible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.80" >
<LinearLayout
android:id="@+id/shareRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:background="#07000000"
android:orientation="horizontal" >
<ImageView
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="15dip"
android:layout_weight=".10"
android:src="@drawable/callout_left" />
<TextView
android:id="@+id/text"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="15dip"
android:layout_weight="0.52"
android:textColor="#636363"
android:textSize="20sp" />
<ImageView
android:id="@+id/right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="15dip"
android:layout_toRightOf="@+id/text"
android:layout_weight=".10"
android:src="@drawable/callout_right" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
AdapterClass:
public class ChatAdapter extends ArrayAdapter<Chat> {
private final Context context;
private final ArrayList<Chat> values;
ImageLoader imageloader;
Datamodel dm;
public ChatAdapter(Context context, ArrayList<Chat> values) {
super(context, R.layout.list_row_layout_even, values);
// TODO Auto-generated constructor stub
this.context = context;
this.values = values;
// imageloader = new ImageLoader(context);
}
public void addMessage(Chat chat) {
values.add(chat);
this.notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.list_row_layout_odd,
parent, false);
LinearLayout root = (LinearLayout) convertView
.findViewById(R.id.even_container);
TextView tv = (TextView) convertView.findViewById(R.id.text);
RoundedImageView oddImg = (RoundedImageView) convertView
.findViewById(R.id.odd_bubble);
ImageView leftimageicon = (ImageView) root.findViewById(R.id.left);
ImageView rightimageicon = (ImageView) root.findViewById(R.id.right);
Typeface fontArial = Typeface.createFromAsset(context.getAssets(),
"fonts/ARIAL.TTF");
SharedPreferences prefs = context.getSharedPreferences(
AppConstants.LOGIN_PREFS, Context.MODE_PRIVATE);
String K = prefs.getString("Member_id", "");
Chat chat = values.get(position);
String t = chat.getRecieverID();
tv.setText(chat.getMessage());
tv.setTypeface(fontArial);
AQuery aq = new AQuery(context);
if (chat.getSenderID().equals(prefs.getString("Member_id", ""))) {
root.setBackgroundColor(Color.parseColor("#07000000"));
tv.setTextColor(Color.parseColor("#636363"));
tv.setBackgroundColor(Color.parseColor("#00ad9a"));
leftimageicon.setVisibility(View.GONE);
rightimageicon.setVisibility(View.VISIBLE);
oddImg.setVisibility(View.GONE);
} else {
root.setBackgroundColor(Color.parseColor("#07000000"));
tv.setTextColor(Color.parseColor("#bdbdbd"));
tv.setBackgroundColor(Color.parseColor("#ffffff"));
oddImg.setVisibility(View.VISIBLE);
aq.id(oddImg).image(
"http://api.lociiapp.com/TransientStorage/" + K + ".jpg");
leftimageicon.setVisibility(View.VISIBLE);
rightimageicon.setVisibility(View.GONE);
oddImg.setVisibility(View.VISIBLE);
}
return convertView;
}
}
This is my adapter class i have textview whose id is text i want set left and right margin of textview Programmatically i mean say that if it will evencallout then margin should left or if right then margin should right please help me how i will ac-chive this i am trying to implement but not understand