哈哈哈就只会回这句,实现如下

首先要在app/build.gradle中加依赖库

compile 'com.android.support:recyclerview-v7:23.4.0'要跟上面一样版本

接着主xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#d8e0e8"android:orientation="vertical"><android.support.v7.widget.RecyclerViewandroid:id="@+id/msg_recyclear_view"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><EditTextandroid:id="@+id/input_text"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:hint="来撩我啊 (●'◡'●)ノ♥ "android:maxLines="2" /><Buttonandroid:id="@+id/send"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="骚他/她" /></LinearLayout>
</LinearLayout>

新建定义消息的实体类Msg。

package com.graduationdesign.pxc.wefuck;import java.security.PublicKey;public class Msg {public static final int TYPE_RECIVED = 0;public static final int TYPE_SENT = 1;private String content;private int type;public Msg(String content, int type) {this.content = content;//消息内容this.type = type;//消息类型}public String getContent() {return content;}public int getType() {return type;}
}

接着新建msg_item.xml来保存消息框的布局,使收到消息居左,发出居右

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:padding="10dp"><LinearLayoutandroid:id="@+id/left_layout"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="left"android:background="@drawable/message_left"><TextViewandroid:id="@+id/left_msg"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_margin="10dp"android:textColor="#000"/></LinearLayout><LinearLayoutandroid:id="@+id/right_layout"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:background="@drawable/message_right"><TextViewandroid:id="@+id/right_msg"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_margin="10dp"android:textColor="#000"/></LinearLayout>
</LinearLayout>

新建RecyclerView的适配器类,新建类MsgAdapter.java

package com.graduationdesign.pxc.wefuck;import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;import java.util.List;public class MsgAdapter extends RecyclerView.Adapter<MsgAdapter.ViewHolder>{private List<Msg> mMsgList;static class ViewHolder extends RecyclerView.ViewHolder{LinearLayout leftLayout;LinearLayout rightLayout;TextView leftMsg;TextView rightMsg;public ViewHolder(View view){super(view);leftLayout=(LinearLayout)view.findViewById(R.id.left_layout);rightLayout=(LinearLayout)view.findViewById(R.id.right_layout);leftMsg=(TextView)view.findViewById(R.id.left_msg);rightMsg=(TextView)view.findViewById(R.id.right_msg);}}public MsgAdapter(List<Msg> msgList) {mMsgList=msgList;}@Overridepublic ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.msg_item,parent,false);return  new ViewHolder(view);}@Overridepublic void onBindViewHolder(ViewHolder holder, int position) {Msg msg=mMsgList.get(position);if (msg.getType()==Msg.TYPE_RECIVED){//如果是收到的消息,则显示在左边的消息布局,将右边的消息布局隐藏holder.leftLayout.setVisibility(View.VISIBLE);holder.rightLayout.setVisibility(View.GONE);holder.leftMsg.setText(msg.getContent());}else if(msg.getType()==Msg.TYPE_SENT){//如果是发出的消息,则显示在右边的消息布局,将左边的消息布局隐藏holder.rightLayout.setVisibility(View.VISIBLE);holder.leftLayout.setVisibility(View.GONE);holder.rightMsg.setText(msg.getContent());}}@Overridepublic int getItemCount() {return mMsgList.size();}}

最后修改主类

package com.graduationdesign.pxc.wefuck;import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;import java.util.ArrayList;
import java.util.List;public class MainActivity extends AppCompatActivity {private List<Msg> msgList = new ArrayList<>();private EditText inputText;private Button send;private RecyclerView msgRecyclerView;private MsgAdapter adapter;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initMsgs();//初始化消息数据inputText = (EditText) findViewById(R.id.input_text);send = (Button) findViewById(R.id.send);msgRecyclerView = (RecyclerView) findViewById(R.id.msg_recyclear_view);LinearLayoutManager layoutManager = new LinearLayoutManager(this);msgRecyclerView.setLayoutManager(layoutManager);adapter = new MsgAdapter(msgList);msgRecyclerView.setAdapter(adapter);send.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String content = inputText.getText().toString();String conre = "嗯,你多喝热水";if (!"".equals(content)) {Msg msg = new Msg(content, Msg.TYPE_SENT);msgList.add(msg);adapter.notifyItemInserted(msgList.size() - 1);//当有新消息时,刷新ListView中的显示msgRecyclerView.scrollToPosition(msgList.size() - 1);//将ListView定位到最后一行inputText.setText("");//清空输入框中的内容Msg msg0 = new Msg(conre, Msg.TYPE_RECIVED);msgList.add(msg0);adapter.notifyItemInserted(msgList.size() - 1);//当有新消息时,刷新ListView中的显示msgRecyclerView.scrollToPosition(msgList.size() - 1);//将ListView定位到最后一行inputText.setText("");//清空输入框中的内容}}});}private void initMsgs() {Msg msg1 = new Msg("你好呀,小可爱。", Msg.TYPE_RECIVED);msgList.add(msg1);Msg msg2 = new Msg("弱弱的问,你谁啊?", Msg.TYPE_SENT);msgList.add(msg2);Msg msg3 = new Msg("你猜。", Msg.TYPE_RECIVED);msgList.add(msg3);}
}

就这样,一个只会回复

"嗯,你多喝热水"

的伪机器人聊天框就好了

尬聊器(伪聊天机器人)相关推荐

  1. 开源、免费、无需注册、打开即聊的人工智能聊天机器人(HuggingChat)

    文章目录 开源.免费.无需注册.打开即聊的人工智能聊天机器人(HuggingChat) 开源.免费.无需注册.打开即聊的人工智能聊天机器人(HuggingChat) Hugging Face是一个机器 ...

  2. python——wxpy模块实现微信尬聊(基于图灵机器人)

    wxpy(微信机器人)是在itchat基础上开发的微信个人功能服务API,基本可以实现微信各种拓展功能, API文档http://wxpy.readthedocs.io/zh/latest/index ...

  3. python 图灵 微信 菜谱_python——wxpy模块实现微信尬聊(基于图灵机器人)-Go语言中文社区...

    wxpy(微信机器人)是在itchat基础上开发的微信个人功能服务API,基本可以实现微信各种拓展功能, 支持pip安装,适用2.7以及3.4-3.6的python版本 通过# 导入模块 from w ...

  4. 简单几行代码看两个机器人尬聊

    最近两天肥学迷恋上了各种强大的api前两天还写了一个调用api的 <python模拟萌妹音让室友疯狂吃鸡> 大家有空可以去看看哦!这不今天又找到了智能聊天机器人的api 又会发现哪些有趣的 ...

  5. 人工智能标记语言AIML聊天机器人:产生、种类、应用、实例、AIML概述、知识库、公司、业界(20k字经典收藏版)...

    目录 一.聊天机器人(chatbots)的产生.盛行.中文版 二.聊天机器人种类及应用场景简介 三.聊天机器人相关疑问与常见实例 四.人工智能标记语言(AIML)概述(Dr.理查德S.华勒斯Richa ...

  6. 人工智能标记语言AIML聊天机器人:…

    人工智能标记语言AIML聊天机器人:产生.种类.应用.实例.AIML概述.知识库.公司.业界(20k字经典收藏版) 秦陇纪10译编 聊天机器人(chatterbot)是一个用来模拟人类对话或聊天的程序 ...

  7. 机器人对话常用语模板_聊天机器人的技术原理和未来的发展

    近年来,人工智能越来越火,那你们真的知道人工智能吗? 一.人工智能是什么 人工智能(Artificial Intelligence),英文缩写为AI.它是研究.开发用于模拟.延伸和扩展人的智能的理论. ...

  8. 什么是人工智能,聊天机器人主要解决哪些问题?

    一.人工智能是什么 人工智能(Artificial Intelligence),英文缩写为AI.它是研究.开发用于模拟.延伸和扩展人的智能的理论.方法.技术及应用系统的一门新的技术科学. 李开复 对人 ...

  9. nonebot2聊天机器人插件9:定时提醒器timing

    nonebot2聊天机器人插件9:定时提醒器timing 1. 插件用途 2. 目录结构 3. 实现难点与解决方案 3.1 定时器 3.2 调用bot的api发送消息 4. 代码实现 5. 插件配图 ...

最新文章

  1. 计算机组成原理——知识结构体系
  2. Java Code Convention Rules
  3. Chrome 提标 您的浏览器限制了第三方Cookie...解决方法
  4. 有人能用外行人解释什么是JSONP吗? [重复]
  5. 【页面传值6种方式】- 【JSP 页面传值方法总结:4种】 - 【跨页面传值的几种简单方式3种】...
  6. Python学习笔记(二)——HelloWorld
  7. Android代码片段:验证数据
  8. 高级/专家工程师职位和面试题
  9. 学生签到系统c代码_C语言实现简单学生学籍管理系统
  10. 不用asp.net MVC,用WebForm照样能够实现MVC
  11. 1190 最小公倍数之和 V2
  12. bootstrap switch只出现一个对号_python:34.第一个只出现一次的字符位置
  13. java中的map是什么_转载java中Map的详解
  14. 1.1.27 word表格里的文字不显示
  15. linux面试题线程与进程,​一道面试题:说说进程和线程的区别
  16. 【转】Gnuplot基本介绍
  17. Java Hook简洁实用教程
  18. 基于python实现全网视频解析--javaWeb篇
  19. The Bequeath Protocol Adapter [ID 16653.1]
  20. android实现地图功能实现,Android快速实现地图功能(不仅快!而且小!)

热门文章

  1. You're Not Late! You're Not Early
  2. java8新特性七-Date Time API
  3. 携手抗击疫情,雀巢大家庭在行动
  4. CRC32算法逆向 lebel:基本过程 / 数据表过程(模二过程) / CRC校验 / str转int
  5. Fragment的懒加载与生命周期详解
  6. 揭秘Pinterest模式生态:半年涌10家受困内容(转)
  7. 关机切换用户后显示远程计算机,系统远程关机权限的设置
  8. 事理图谱,下一代知识图谱
  9. PAT 自学题解 B1033【测试点4超时】
  10. Mac OS 12.3系统版本使用AccessClient堡垒机跳转闪退问题记录