动态地添加到horizontalscrollview [英] Dynamically add to horizontalscrollview
问题描述
我已经按照一些网上的教程,告诉你如何创建多个XML文件的静态horizontalscrollview。
I've followed a few tutorials online that show you how to create a static horizontalscrollview with multiple xml files.
不过,我希望能够从数据库中抓取的内容,与内容填充新视图(从股票XML布局),然后将其添加到horizontalscrollview。
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.
有没有告诉你如何动态视图添加到horizontalscrollview?任何教程
Are there any tutorials that show you how to add dynamic views to a horizontalscrollview?
推荐答案
这是容易的,
您HorizontalScrollView必须包含像的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);
}
这篇关于动态地添加到horizontalscrollview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!