Я хочу выровнять список влево и вправо внутри RelativeLayout
, как это сделано в приложениях IM.Ориентация списка влево и вправо списка
Моя проблема в том, что вещи становятся случайными. Иногда, когда m.getme() == 0
, тогда загружался его макет msg_row_he.xml
, но иногда загружался его msg_row_me.xml
. И выравнивание listview меняется при каждом прокрутке. Кто-нибудь может понять, что происходит?
msgAdapter.java(GetView метод)
public View getView(int position, View convertView, ViewGroup parent) {
// getting data for the row
MSList m = listItems.get(position);
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null){
if(m.getme() == 0){
convertView = inflater.inflate(R.layout.msg_row_he, null);
}else{
convertView = inflater.inflate(R.layout.msg_row_me, null);
}
}
ImageView pp = (ImageView) convertView
.findViewById(R.id.ind_pp);
TextView msgcon = (TextView) convertView.findViewById(R.id.ind_msgcon);
TextView msgtime = (TextView) convertView.findViewById(R.id.ind_msgtime);
// thumbnail image
new ImageLoadTask(m.getppUrl(),pp).execute();
// content
msgcon.setText(m.getmsgcon());
// time
msgtime.setText(String.valueOf(m.getmsgtime()));
convertView.setTag(m);
return convertView;
}
msg_row_me.xml(выравнивание по правому краю)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_row_selector"
android:padding="8dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<!-- Content -->
<TextView
android:id="@+id/ind_msgcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#fbfbfb"
android:textColor="@color/msgcon"
android:textSize="@dimen/msgcon" />
<!-- Thumbnail Image -->
<ImageView
android:id="@+id/ind_pp"
android:layout_width="45dp"
android:layout_height="45dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<!-- Message Time -->
<TextView
android:id="@+id/ind_msgtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/msgtime"
android:textSize="@dimen/msgtime" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
msg_row_he.xml(слева выравнивается)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_row_selector"
android:padding="8dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="right"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal" >
<!-- Thumbnail Image -->
<ImageView
android:id="@+id/ind_pp"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginRight="8dp" />
<!-- Content -->
<TextView
android:id="@+id/ind_msgcon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#fbfbfb"
android:textColor="@color/msgcon"
android:textSize="@dimen/msgcon" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:orientation="horizontal" >
<!-- Message Time -->
<TextView
android:id="@+id/ind_msgtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/msgtime"
android:textSize="@dimen/msgtime" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Попробуйте это - http://javapapers.com/android/android-chat-bubble/ –