动态地添加到horizo​​ntalscrollview [英] Dynamically add to horizontalscrollview

查看:155
本文介绍了动态地添加到horizo​​ntalscrollview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照一些网上的教程,告诉你如何创建多个XML文件的静态horizo​​ntalscrollview。

I've followed a few tutorials online that show you how to create a static horizontalscrollview with multiple xml files.

不过,我希望能够从数据库中抓取的内容,与内容填充新视图(从股票XML布局),然后将其添加到horizo​​ntalscrollview。

However I would like to be able to grab content from a database, fill a new view (from a stock xml layout) with the content and then add it to the horizontalscrollview.

有没有告诉你如何动态视图添加到horizo​​ntalscrollview?任何教程

Are there any tutorials that show you how to add dynamic views to a horizontalscrollview?

推荐答案

这是容易的,

您Horizo​​ntalScrollView必须包含像的LinearLayout或RelativeLayout的容器,抢一个实例在活动的布局,并根据需要添加的看法...

Your HorizontalScrollView must contain a container like a LinearLayout or a RelativeLayout, grab an instance to that Layout in your activity, and add the views as required...

LinearLayout yourLayout = (LinearLayout)findViewById(R.id.someID);

,然后通过在数据库中的项目数和迭代不断增加的意见,你的布局,直到像为此...

and then iterate through the number of items in your database and keep adding the views to your Layout until end like this...

for (int i = 0; i < yourData.size(); i++) {             
  TextView tv = new TextView(getApplicationContext());
  tv.setText(yourData.get(i));
  yourLayout.addView(tv);
}

这篇关于动态地添加到horizo​​ntalscrollview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆