1、主布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.android09.MainActivity" tools:ignore="MergeRootFrame" >    <Button android:id="@+id/bt" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="点击我" />    <TextView android:id="@+id/tv" android:text="哈哈哈哈哈哈我是哈哈哈哈布局文件中放置一个TextView,给它添加scrollbars和fadeScrollbars两个属性" android:layout_width="match_parent" android:layout_height="wrap_content" android:fadeScrollbars="false" android:scrollbars="vertical" /></LinearLayout>

2、主要代码 :

package com.android09; import android.app.Activity; import android.os.Bundle; import android.text.method.ScrollingMovementMethod; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class MainActivity extends Activity { Button button ; TextView textView ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) findViewById( R.id.bt ) ; button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { String string = "在Ubuntu中有如下几个文件可以设置环境变量/etc/profile:在登录时,"                        + "操作系统定制用户环境时使用的第一个文件,此文件为系统的每个用户设置环境信息,当用户第一次登录时,"                        + "该文件被执行./etc/environment:在登录时操作系统使用的第二个文件,"                        + "系统在读取你自己的profile前,设置... " ; refreshLogView( string ); } }); textView = (TextView) findViewById( R.id.tv ) ; textView.setMovementMethod(ScrollingMovementMethod.getInstance()); } void refreshLogView(String msg){ textView.append(msg); int offset=textView.getLineCount()*textView.getLineHeight(); if(offset>textView.getHeight()){ textView.scrollTo(0,offset-textView.getHeight()); } } }


3、运行效果:

在给 TextView 添加文字时,textview 会自动滚动到最后一条。

更多相关文章

  1. Android(安卓)控件之Gallery图片集
  2. android 获取文件的扩展名和去掉文件的扩展名
  3. android混淆出错更新progurad
  4. GridView的属性
  5. Android基础知识总结
  6. 修改 Android(安卓)开机 LOGO
  7. Android(安卓)Studio中与网站通信
  8. 转:Android(安卓)设置EditText光标颜色及粗细
  9. NPM 和webpack 的基础使用

随机推荐

  1. android:跳转,Intent,有无返回值
  2. Android_相对布局的相关属性RalativeLayo
  3. 关于android里面的几种Selector状态
  4. 2019-01-07
  5. android简单的夜间模式
  6. Android(安卓)intent-filter 简单用法
  7. APIDEMO TABLELAYOUT
  8. Android(安卓)网站资源收集大全
  9. Android(安卓)自带图标库 android.R.draw
  10. APIDEMO TABLELAYOUT