如何将图像添加到basic4android中的scrollview

时间:2014-08-02 14:31:59

标签: scrollview basic4android

我想在basic4android中的ScrollView中加载一些图片。这只发生过一次。

我的代码:

Activity.LoadLayout("main")
Dim b As Bitmap
    Dim iv As ImageView
For i=1 To 10
b.Initialize(File.DirAssets,"1.png")
iv.Initialize("")
iv.Bitmap = b
ScrollView1.Panel.AddView(iv,30dip,30dip,212,64)
Next

而不是10张图片,我的ScrollView中只显示一张图片。 我需要你的帮助。感谢。

2 个答案:

答案 0 :(得分:0)

For i = 10
    Dim iv As ImageView 'create an ImageView for each bitmap
    iv.Initialize("") 'not interested in any events so we pass empty string.
    Dim bd As BitmapDrawable
    bd.Initialize(Bitmaps.Get(i))
    iv.Background = bd 'set the background of the image view.
    'add the image view to the scroll bar internal panel.
    ScrollView1.Panel.AddView(iv, 5dip, 5dip + i * 200dip, ScrollView1.Width - 10dip, 190dip)
Next

尝试以上“应该”工作的代码,我不在B4A附近测试它,但所有代码看起来都在我的例子中。

答案 1 :(得分:0)

始终在顶部30dip上添加视图

ScrollView1.Panel.AddView(iv,30dip,30dip,212,64)

更改值

ScrollView1.Panel.AddView(<Image>,<Left>,<Top>,<H>,<W>)