Android中ScrollView用法介绍

来源:互联网 发布:js字符串反转 编辑:程序博客网 时间:2024/05/20 05:09

ScrollView(滚动视图)是实现滚动的一个控件,只需要将需要滚动的控件添加到ScrollView中即可!ScrollView可以在代码中进行设置,也可以在XML布局文件中进行设置!

 

1.Activity文件如下:

import android.app.Activity;
import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.TextView;

public class ScrollViewActivity extends Activity {
  
  
 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ScrollView scrollView=new ScrollView(this);
        String s="中华儿女显神威,华夏大地起风云!男儿立志出乡关,誓不成名死不休!";
        String msg="";
       
        TextView textView=new TextView(this);
        for(int t=0;t<20;t++)

{
          msg+=s;
        textView.setText(msg);
        textView.setTextSize(23);
        scrollView.addView(textView);
        setContentView(scrollView);

}
       
    }


}