Android实现ScrollView动态显示文字

来源:互联网 发布:问卷星快速录入数据 编辑:程序博客网 时间:2024/05/21 00:17

需求说明:

这个需求就是ScrollView中从上往下一行一行的显示文本,都显示完后还可以滑动来查看,例如病毒查杀软件中,扫描的过程

需要动态的显示出来,显示完毕后可以手动滑动查看

原理介绍:

很简单,在ScrollView中有一个垂直的LinearLayout,代码中动态向LinearLayout中添加TextView即可:addView(TextView)

示例代码:

1.ScrollView

<!--注意ScrollView只能有一个孩子-->  <ScrollView      android:layout_width="match_parent"      android:layout_height="match_parent">      <LinearLayout          android:id="@+id/ll_content"          android:layout_width="match_parent"          android:layout_height="match_parent"          android:orientation="vertical">      </LinearLayout>  </ScrollView>
2.向LinearLayout动态添加TextView

//得到LinearLayoutLinearLayout ll_content;ll_content = (LinearLayout) findViewById(R.id.ll_content);//创建TextViewTextView textView = new TextView(KillVirusActivity.this);textView.setTextColor(Color.WHITE);//设置显示内容textView.setText("扫描:" +scanVirus.apkName);//添加到LinearLayout中ll_content.addView(textView);


0 0
原创粉丝点击