【发布时间】:2015-12-10 17:40:19
【问题描述】:
我在右侧有一个类似图片的列表视图:
此列表视图用于消息传递。我想知道如何反转发件人消息的布局。
更详细。 我需要来自发件人的消息:
IMAGEVIEW 对齐到屏幕右侧。
标题向右对齐,但在图像视图的左侧。
要在图像视图和标题下方向右但向左对齐的消息。
时间对齐到每个项目的布局左侧和底部。(未在图像中显示)
基本上我需要现有的布局来反转发件人的消息。 我有代码,但目前不在我的电脑前。 如果需要代码,我很乐意添加它。 我正在使用基本的 BaseAdapter 来加载列表视图。
添加
这是自定义行布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="horizontal"
android:paddingTop="10dp"
android:weightSum="1"
android:id="@+id/chatView">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:id="@+id/messenger_pic"
android:layout_marginLeft="10dp"
android:src="@drawable/profile" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:layout_width="220dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/messenger_name"
android:layout_marginLeft="10dp"
android:textStyle="bold"
android:textColor="#000000" />
<TextView
android:layout_width="match_parent"
android:layout_height="118dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Small Text"
android:id="@+id/messenger_message"
android:layout_marginLeft="10dp"
android:textStyle="normal" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/messenger_time"
android:layout_gravity="bottom"
android:textAlignment="center"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
这是我的 BaseAdapter 类:
class Messengeradapt extends BaseAdapter {
ArrayList<chat_messages> messageArray = M.messageArray;
@Override
public int getCount() {
return messageArray.size();
}
@Override
public Object getItem(int position) {
return messageArray.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
chat_messages temp = messageArray.get(position);
LayoutInflater inflater = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.chat_view, parent, false);
TextView name = (TextView) row.findViewById(R.id.messenger_name);
TextView message = (TextView) row.findViewById(R.id.messenger_message);
TextView time = (TextView) row.findViewById(R.id.messenger_time);
ImageView picture = (ImageView) row.findViewById(R.id.messenger_pic);
if ((e.FirstnName + " " + e.LastName).equals(temp.from_name)){
String imageUrl = "http://192.168.1.52/android_connect/pictures/"+ e.FirstnName + " " + e.LastName + ".jpg";
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity()));
imageLoader.displayImage(imageUrl, picture);
name.setText(e.FirstnName + " " + e.LastName);
message.setText(temp.message);
time.setText(temp.time);
}
else
{
String imageUrl = "http://192.168.1.52/android_connect/pictures/"+ C.contactname + ".jpg";
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity()));
imageLoader.displayImage(imageUrl, picture);
name.setText(C.contactname);
message.setText(temp.message);
time.setText(temp.time);
}
return row;
}
}
【问题讨论】:
标签: android android-layout listview android-studio