У моего пользовательского списка-списка есть своего рода уникальная проблема, и я не могу отслеживать, где проблема. Пользовательский список-представление предназначен для приложения чата, которое я создаю, в котором я динамически добавляю текстовые представления с введенными пользователем сообщениями. При добавлении каждого текстового вида представление списка перемещается в левую часть экрана, а текстовый вид становится срезанным с левой стороны, я много искал, что может быть причиной, но не удалось найти, может кто-нибудь поможет мне в этом вопросе? Изображение показывает пробел, который увеличивается с правой стороны с каждой записью. и вот XML code` Пользовательские элементы ListView, перемещающие список влево?
<RelativeLayout
android:id="@+id/chatheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/headershowfriends" >
<TextView
android:id="@+id/namechatfriend"
style="@style/Text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="demo" />
<ImageView
android:id="@+id/frdstatus"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:background="@drawable/online" />
</RelativeLayout>
<ListView
android:id="@+id/myList"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="@+id/msgboxll"
android:layout_below="@+id/chatheader"
android:layout_marginBottom="50dp"
android:layout_marginLeft="10dp"
android:dividerHeight="0dp"
android:divider="@null"
android:fitsSystemWindows="true" />
<LinearLayout
android:id="@+id/msgboxll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearchat"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/headershowfriends"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="@+id/smiles"
android:layout_width="20dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="1dp"
android:layout_weight="0.1"
android:background="@drawable/chat_smile" />
<EditText
android:id="@+id/messageBx"
style="@drawable/edittext"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:layout_marginTop="2dp"
android:layout_weight="0.80" >
</EditText>
<Button
android:id="@+id/sendBtn"
style="@style/button_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="3dp"
android:layout_weight="0.1"
android:text="@string/send" />
</LinearLayout>
<com.pack.coderzheaven.SlidingPanel
android:id="@+id/popup_smilywindow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/blackbckgnd"
android:gravity="left"
android:orientation="vertical"
android:visibility="invisible" >
<GridView
android:id="@+id/gridViewsmily"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="30dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="5"
android:verticalSpacing="10dp" >
</GridView>
</com.pack.coderzheaven.SlidingPanel>
</LinearLayout>
`
и это мой адаптер `
public class ChatMessageAdapter extends ArrayAdapter<Chat>
{
List<Chat>listmsg=new ArrayList<Chat>();
Activity context;
Bitmap bitmapfriend,bitmapuser;
public ChatMessageAdapter(Activity context,List<Chat> listmsg, Bitmap friendimage, Bitmap userimage)
{
super(context, R.layout.list_row_layout_even, listmsg);
this.listmsg=listmsg;
this.context=context;
this.bitmapfriend=friendimage;
this.bitmapuser=userimage;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
try
{
try
{
LayoutInflater inflater = context.getLayoutInflater();
String type=listmsg.get(position).getType();
if(type.contentEquals("even"))
{
convertView = inflater.inflate(R.layout.list_row_layout_even, parent, false);
TextView textLabel = (TextView) convertView.findViewById(R.id.text);
textLabel.setText(listmsg.get(position).getMessageSpannable());
ImageView image=(ImageView) convertView.findViewById(R.id.rightProfilePic);
if (bitmapuser==null)
{
}
else
{
image.setImageBitmap(bitmapuser);
}
}
else if(type.contentEquals("odd"))
{
convertView = inflater.inflate(R.layout.list_row_layout_odd, parent, false);
TextView textLabel = (TextView) convertView.findViewById(R.id.text);
textLabel.setText(listmsg.get(position).getMessageSpannable());
ImageView image=(ImageView) convertView.findViewById(R.id.leftProfilePic);
image.setImageBitmap(bitmapfriend);
}
}
catch (Exception e)
{
throw new IOException("Error connecting");
}
}
catch (Exception e)
{
}
return (convertView);
}
} `
Не связанный с вашим вопросом, но ознакомьтесь с http://developer.android.com/reference/android/widget/BaseAdapter.html#getItemViewType(int) вместо использования нечетного/четного индекса, чтобы определить тип представления для использовать. – Kuffs