Android 开发笔记___textview_聊天室效果

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical" android:layout_width="match_parent"
 4     android:layout_height="match_parent">
 5
 6     <TextView
 7         android:layout_width="match_parent"
 8         android:layout_height="wrap_content"
 9         android:id="@+id/tv_control"
10         android:layout_marginTop="20dp"
11         android:gravity="center"
12         android:text="聊天室效果,点击添加聊天记录,长按删除聊天记录"
13         />
14
15     <LinearLayout
16         android:orientation="vertical"
17         android:layout_width="match_parent"
18         android:layout_height="200dp">
19
20         <TextView
21             android:layout_width="match_parent"
22             android:layout_height="match_parent"
23             android:id="@+id/tv_bbs"
24             android:layout_marginTop="20dp"
25             android:scrollbars="vertical"
26             android:textColor="@color/text_color"
27             android:textSize="17sp"/>
28
29     </LinearLayout>
30
31 </LinearLayout>

java

 1 package com.example.alimjan.hello_world;
 2
 3 import android.app.Activity;
 4 import android.content.Context;
 5 import android.content.DialogInterface;
 6 import android.content.Intent;
 7 import android.os.Bundle;
 8 import android.support.annotation.Nullable;
 9 import android.support.v7.app.AppCompatActivity;
10 import android.text.format.DateUtils;
11 import android.text.method.ScrollingMovementMethod;
12 import android.view.Gravity;
13 import android.view.View;
14 import android.widget.TextView;
15
16 /**
17  * Created by alimjan on 6/30/2017.
18  */
19
20 public class class__2_3_1_2 extends AppCompatActivity implements DialogInterface.OnClickListener,View.OnLongClickListener, View.OnClickListener {
21
22     private TextView tv_bbs,tv_control;
23
24     @Override
25     protected void onCreate(@Nullable Bundle savedInstanceState) {
26         super.onCreate(savedInstanceState);
27         setContentView(R.layout.code_2_3_1_2);
28
29         tv_control = (TextView) findViewById(R.id.tv_control);
30         tv_control.setOnClickListener(this);
31         tv_control.setOnLongClickListener(this);
32         tv_bbs = (TextView) findViewById(R.id.tv_bbs);
33         tv_bbs.setOnClickListener(this);
34         tv_bbs.setOnLongClickListener(this);
35         tv_bbs.setGravity(Gravity.LEFT|Gravity.BOTTOM);
36         tv_bbs.setLines(8);
37         tv_bbs.setMaxLines(8);
38         tv_bbs.setMovementMethod(new ScrollingMovementMethod());
39     }
40
41     private String[] mChatStr={"你吃饭了吗honey?","今天天气超级热!你们那儿呢?","我中奖啦!","走不走看电影~","你在干什么?"};
42
43     public static void startHome(Context mContext) {
44         Intent intent = new Intent(mContext, class__2_3_1_2.class);
45         mContext.startActivity(intent);
46     }
47
48     @Override
49     public void onClick(DialogInterface dialog, int which) {
50
51     }
52
53     @Override
54     public boolean onLongClick(View v) {
55         if(v.getId() == R.id.tv_control || v.getId() == R.id.tv_bbs){
56             tv_bbs.setText("");
57         }
58         return true;
59     }
60
61     @Override
62     public void onClick(View v) {
63         if(v.getId() == R.id.tv_control || v.getId() == R.id.tv_bbs){
64             int random = (int) ((Math.random()*10)%5);
65             String newstr = String.format("%s\n%s%s",tv_bbs.getText().toString(), DateUtil.getCurDateStr(),mChatStr[random]);
66             tv_bbs.setText(newstr);
67         }
68     }
69 }
时间: 2024-08-06 20:00:21

Android 开发笔记___textview_聊天室效果的相关文章

【视频】零基础学Android开发:蓝牙聊天室APP(一)

零基础学Android开发:蓝牙聊天室APP第一讲 1. Android介绍与环境搭建:史上最高效Android入门学习 1.1 Google的大小战略 1.2 物联网与云计算 1.3 智能XX设备 1.4 Android发展前景 1.5 Android企业需求与就业薪资 1.6 Android框架介绍 1.7 搭建Android开发环境 1.8 Android SDK文件夹具体解释 1.9 开发第一个App:HelloWorld 1.10 App应用程序文件夹具体解释 在线收看:http://

【视频】零基础学Android开发:蓝牙聊天室APP(三)

零基础学Android开发:蓝牙聊天室APP第三讲 3.1 ImageView.ImageButton控件详解 3.2 GridView控件详解 3.3 SimpleAdapter适配器详解 3.4 事件监听器:OnItemClickListener 3.5 输入和显示表情图像 在线收看:http://www.3g-edu.org/news/video023.htm 视频下载:http://pan.baidu.com/s/1kTmiNqf

【视频】零基础学Android开发:蓝牙聊天室APP(四)

零基础学Android开发:蓝牙聊天室APP第四讲 4.1 ListView控件的使用 4.2 BaseAdapter详解 4.3 ListView分布与滚动事件 4.4 ListView事件监听器:OnItemClickedListener 在线收看:http://www.3g-edu.org/news/video026.htm 视频下载:http://pan.baidu.com/s/1jGkjDGE

【视频】零基础学Android开发:蓝牙聊天室APP(二)

零基础学Android开发:蓝牙聊天室APP第二讲 2.1 课程内容应用场景 2.2 Android UI设计 2.3 组件布局:LinearLayout和RelativeLayout 2.4 TextView.EditText.Button控件 2.5 文本信息的隐藏和显示 2.6 输入和显示表情图像 在线收看:http://www.3g-edu.org/news/video022.htm 视频下载:http://pan.baidu.com/s/1mgHoObu

Android 开发笔记___textvieww__跑马灯效果

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:l

Android开发笔记(一百一十一)聊天室中的Socket通信

Socket通信 基本概念 对于程序开发来说,网络通信的基础就是Socket,但因为是基础,所以用起来不容易,今天我们就来谈谈Socket通信.计算机网络有个大名鼎鼎的TCP/IP协议,普通用户在电脑上设置本地连接的ip时,便经常看到下图的弹窗,注意红框部分已经很好地描述了TCP/IP协议的作用. TCP/IP是个协议组,它分为三个层次:网络层.传输层和应用层: 网络层包括:IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议. 传输层包括:TCP协议.UDP协议. 应用层包括:HT

【转】Android开发笔记(序)写在前面的目录

原文:http://blog.csdn.net/aqi00/article/details/50012511 知识点分类 一方面写写自己走过的弯路掉进去的坑,避免以后再犯:另一方面希望通过分享自己的经验教训,与网友互相切磋,从而去芜存菁进一步提升自己的水平.因此博主就想,入门的东西咱就不写了,人不能老停留在入门上:其次是想拾缺补漏,写写虽然小众却又用得着的东西:另外就是想以实用为主,不求大而全,但求小而精:还有就是有的知识点是java的,只是Android开发也会经常遇上,所以蛮记下来.个人的经

Android开发笔记(一百三十四)协调布局CoordinatorLayout

协调布局CoordinatorLayout Android自5.0之后对UI做了较大的提升,一个重大的改进是推出了MaterialDesign库,而该库的基础即为协调布局CoordinatorLayout,几乎所有的design控件都依赖于该布局.协调布局的含义,指的是内部控件互相之前的动作关联,比如在A视图的位置发生变化之时,B视图的位置也按照某种规则来变化,仿佛弹钢琴有了协奏曲一般. 使用CoordinatorLayout时,要注意以下几点:1.导入design库:2.根布局采用androi

Android开发笔记(一百三十二)矢量图形与矢量动画

矢量图形VectorDrawable 与水波图形RippleDrawable一样,矢量图形VectorDrawable也是Android5.0之后新增的图形类.矢量图不同于一般的图形,它是由一系列几何曲线构成的图像,这些曲线以数学上定义的坐标点连接而成.具体到实现上,则需开发者提供一个xml格式的矢量图形定义,然后系统根据矢量定义自动计算该图形的绘制区域.因为绘图结果是动态计算得到,所以不管缩放到多少比例,矢量图形都会一样的清晰,不像位图那样拉大后会变模糊. 矢量图形的xml定义有点复杂,其结构