Android ListView Rowlayout在自己编码的聊天中 我想做的事

Android ListView Rowlayout在自己编码的聊天中 我想做的事,android,android-layout,chat,Android,Android Layout,Chat,我正在尝试创建一个聊天,它必须与不同行的聊天。对于每一行,我都创建了自己的布局文件,但问题是一行的布局文件不适合屏幕 问题 我需要在行布局中更改什么,以使其符合要求。你会发现代码和我正在尝试的打印屏幕 代码 列表适配器 公共类ChatListAdapter扩展了BaseAdapter{ private ArrayList<String> ContentList; private ArrayList<Integer> Ch

我正在尝试创建一个聊天,它必须与不同行的聊天。对于每一行,我都创建了自己的布局文件,但问题是一行的布局文件不适合屏幕

问题 我需要在行布局中更改什么,以使其符合要求。你会发现代码和我正在尝试的打印屏幕

代码


列表适配器 公共类ChatListAdapter扩展了BaseAdapter{

            private ArrayList<String> ContentList;
            private ArrayList<Integer> ChatUserList;

            private static LayoutInflater inflater = null;

            public ChatListAdapter(Activity activity, ArrayList<String> _ContentList,
                                   ArrayList<Integer> _ChatUserList) {
                        ContentList = _ContentList;
                        ChatUserList = _ChatUserList;
                        inflater = (LayoutInflater) activity
                                               .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            }

            public int getCount() {
                        return ContentList.size();
            }

            public Object getItem(int position) {
                        return position;
            }

            public long getItemId(int position) {
                        return position;
            }

            public View getView(int position, View convertView, ViewGroup parent) {
                        View vi = convertView;
                        TextView tv_text;
                        TextView tv_date;

                        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

                        if (ChatUserList.get(position) == 1) {
                                   // I'm RECIVER -> Message is left align
                                   vi = inflater.inflate(R.layout.rowlayout_leftalign, null);
                                   tv_text = (TextView) vi.findViewById(R.id.tv_chat_leftalign);
                                   tv_date = (TextView) vi.findViewById(R.id.tv_chat_leftalign_date);
                        } else {
                                   // I'm SENDER -> Message is right align
                                   vi = inflater.inflate(R.layout.rowlayout_rightalign, null);
                                   tv_text = (TextView) vi.findViewById(R.id.tv_chat_rightalign);
                                   tv_date = (TextView) vi.findViewById(R.id.tv_chat_rightalign_date);
                        }

                        tv_date.setText(sdf.format(new Date()));
                        tv_text.setText(ContentList.get(position));
                        tv_text.setMaxWidth(((Chat.display.getWidth() / 4) * 3));

                        return vi;
            }
private ArrayList ContentList;
私有ArrayList聊天用户列表;
专用静态充气机=空;
公共ChatListAdapter(活动、ArrayList\u内容列表、,
ArrayList(用户列表){
ContentList=\u ContentList;
ChatUserList=\u ChatUserList;
充气器=(充气器)活动
.getSystemService(上下文布局\充气机\服务);
}
public int getCount(){
返回ContentList.size();
}
公共对象getItem(int位置){
返回位置;
}
公共长getItemId(int位置){
返回位置;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视图vi=转换视图;
text查看电视文本;
文本查看电视节目日期;
SimpleDataFormat sdf=新的SimpleDataFormat(“HH:mm”);
if(ChatUserList.get(position)==1){
//我收到了->消息左对齐
vi=充气机。充气(R.layout.rowlayout_leftalign,null);
tv_text=(TextView)vi.findviewbyd(R.id.tv_chat_leftalign);
tv_date=(TextView)vi.findviewbyd(R.id.tv_chat_leftalign_date);
}否则{
//我是发件人->信息正确对齐
vi=充气机。充气(R.layout.rowlayout_rightalign,空);
tv_text=(TextView)vi.findViewById(R.id.tv_chat_rightalign);
tv_date=(TextView)vi.findViewById(R.id.tv_chat_rightalign_date);
}
tv_date.setText(sdf.format(new date());
tv_text.setText(ContentList.get(position));
tv_text.setMaxWidth(((Chat.display.getWidth()/4)*3));
返回vi;
}
左行布局XML(蓝色气泡)


右行布局XML(红色气泡)


对于这两种XML,添加
android:layout\u width=“fill\u parent”
android:layout\u height=“wrap\u content”
如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:background="@android:color/transparent" 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent" >


等等……

不清楚什么代表红色聊天和蓝色聊天。我通过查看您的代码来提供此ans。查看打印屏幕,您会看到一个蓝色和红色的消息气泡;)这就是我的意思,我确信您在这两种布局中都有问题,实际上形成了一段距离,您无法检测到确切的错误所以我的建议是检查两种布局,主要是布局的宽度/高度部分,在所有项目中彻底对齐左/右部分。希望你能解决你的问题。祝你一切顺利。我重新编码了整个代码。不管它现在如何工作。但绿色的勾号是给你的
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@android:color/transparent" >

    <RelativeLayout
        android:id="@+id/ly_rf_row_l"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="2.5dp"
        android:layout_marginTop="2.5dp"
        android:background="@drawable/shape_leftalign"
        android:paddingBottom="2.5dp"
        android:paddingTop="2.5dp" >

        <TextView
            android:id="@+id/tv_chat_leftalign"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:gravity="left"
            android:paddingBottom="2dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingTop="2dp"
            android:textColor="@android:color/black" />

        <TextView
            android:id="@+id/tv_chat_leftalign_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="-3dp"
            android:layout_marginLeft="-3dp"
            android:layout_toRightOf="@id/tv_chat_leftalign"
            android:paddingLeft="4dp"
            android:paddingRight="4dp"
            android:textColor="@android:color/black"
            android:textSize="8.5dp" />
    </RelativeLayout>

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:background="@android:color/transparent" 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent" >