ساخت عکس تصادفی در بیسیک فور اندروید

با سلام و درود خدمت کاربران عزیز وب سایت 

 

در این ساعت از سایت بنابه در خواست یکی از دوستان قطعه کد عکس تصارفی رو براتون نوشتم و قرار میدم .

 

موفق و سر بلند باشید .

 

#Region  Project Attributes 
	#ApplicationLabel: B4A Example
	#VersionCode: 1
	#VersionName: 
	'SupportedOrientations possible values: unspecified, landscape or portrait.
	#SupportedOrientations: unspecified
	#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Private ImageView1 As ImageView
	Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
	Dim yahoo98 As Int
	yahoo98 = Rnd(1, 4) ' in your case between 1 and 3
	ImageView1.Bitmap = LoadBitmap(File.DirAssets, "image_" & NumberFormat(yahoo98, 2, 0) & ".png")
End Sub

 

توجه : شایان به ذکر می باشد که برای کد بالا شما باید در فولدر files سورس خود ۴ عکس به ترتیب :

 

image_01.png

image_02.png

image_03.png

image_04.png

 

قرار بدبد و یه لی یوت یا لایوت بسازید و درونش ImageView1  و Button1  رو قرار بدید و اسم لایوتتونم به نام ۱ ذخیره کنید .

دیدگاهتان را بنویسید