Text objects not acting correctly

bishmedia

Member
Licensed User
Longtime User
When i run a simple 'contact' view, it loads ok but when i press the first text box the rest shrink as picture 2 shows. When i press the shrunk text boxes they go back to normal.
I did have all my code in the designer but it did it there as well??

Am i missing something??

B4X:
Sub AddViews
   Dim cd As ColorDrawable
   Dim LabelTextSize As Int
   LabelTextSize = 20
   
   cd.Initialize(Colors.White,15)
   
   imgBrapp.Initialize("imgBrapp")
   imgBrapp.Bitmap = (LoadBitmap(File.DirAssets, "splash.jpg"))
   imgBrapp.Gravity = Gravity.FILL
   Activity.AddView(imgBrapp, 20%x, 0%y, 60%x, 15%y)   

   lblContactName.Initialize("lblContactName")
   lblContactName.Color = Colors.Black
   lblContactName.TextSize = LabelTextSize
   lblContactName.TextColor = Colors.White
   lblContactName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   lblContactName.Text = "CONTACT NAME"
   Activity.AddView(lblContactName, 5%x, 15%y, 85%x, 5%y) 'Left, Top, Width, Height   

   txtContactName.Initialize("txtContactName")
   txtContactName.TextSize = 20
   txtContactName.TextColor = Colors.Black
   txtContactName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   txtContactName.Text = ""
   txtContactName.Background=cd
   Activity.AddView(txtContactName, 5%x, 20%y, 85%x, 40dip) 'Left, Top, Width, Height
   
   lblBandName.Initialize("lblBandName")
   lblBandName.Color = Colors.Black
   lblBandName.TextSize = LabelTextSize
   lblBandName.TextColor = Colors.White
   lblBandName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   lblBandName.Text = "BAND NAME"
   Activity.AddView(lblBandName, 5%x, 25%y, 85%x, 5%y) 'Left, Top, Width, Height   

   txtbandName.Initialize("txtBandName")
   txtbandName.TextSize = 20
   txtbandName.TextColor = Colors.Black
   txtbandName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   txtbandName.Text = ""
   txtbandName.Background=cd
   Activity.AddView(txtbandName, 5%x, 30%y, 85%x, 40dip) 'Left, Top, Width, Height   

   lblTelephone.Initialize("lblTelephone")
   lblTelephone.Color = Colors.Black
   lblTelephone.TextSize = LabelTextSize
   lblTelephone.TextColor = Colors.White
   lblTelephone.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   lblTelephone.Text = "TELEPHONE NO."
   Activity.AddView(lblTelephone, 5%x, 35%y, 85%x, 5%y) 'Left, Top, Width, Height   

   txtTelephone.Initialize("txtTelephone")
   txtTelephone.TextSize = 20
   txtTelephone.TextColor = Colors.Black
   txtTelephone.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   txtTelephone.Text = ""
   txtTelephone.Background=cd
   Activity.AddView(txtTelephone, 5%x, 40%y, 85%x, 40dip) 'Left, Top, Width, Height      
   
   lblPostcode.Initialize("lblPostcode")
   lblPostcode.Color = Colors.Black
   lblPostcode.TextSize = LabelTextSize
   lblPostcode.TextColor = Colors.White
   lblPostcode.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   lblPostcode.Text = "POSTCODE"
   Activity.AddView(lblPostcode, 5%x, 45%y, 85%x, 5%y)
   
   txtPostcode.Initialize("txtPostcode")
   txtPostcode.TextSize = 20
   txtPostcode.TextColor = Colors.White
   txtPostcode.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
   txtPostcode.Text = ""
   txtPostcode.Background=cd
   Activity.AddView(txtPostcode, 5%x, 50%y, 40%x, 40dip)   
End Sub
 

Attachments

  • 1.jpg
    36.7 KB · Views: 249
  • 2.jpg
    36 KB · Views: 286

bishmedia

Member
Licensed User
Longtime User
REALLY!!!
So do i call to draw every text & label like....

B4X:
Sub Activity_Create(FirstTime As Boolean)
   AddViews1
   AddViews2
   AddViews3
        etc.............

End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In the routine you must Dim and Initialize a new ColorDrawable object for each EditText view, that means four times in your AddView routine !
B4X:
Sub AddViews
    Dim LabelTextSize As Int
    LabelTextSize = 20
    
    imgBrapp.Initialize("imgBrapp")
    imgBrapp.Bitmap = (LoadBitmap(File.DirAssets, "splash.jpg"))
    imgBrapp.Gravity = Gravity.FILL
    Activity.AddView(imgBrapp, 20%x, 0%y, 60%x, 15%y)    

    lblContactName.Initialize("lblContactName")
    lblContactName.Color = Colors.Black
    lblContactName.TextSize = LabelTextSize
    lblContactName.TextColor = Colors.White
    lblContactName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    lblContactName.Text = "CONTACT NAME"
    Activity.AddView(lblContactName, 5%x, 15%y, 85%x, 5%y) 'Left, Top, Width, Height    

    txtContactName.Initialize("txtContactName")
    txtContactName.TextSize = 20
    txtContactName.TextColor = Colors.Black
    txtContactName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    txtContactName.Text = ""
    Dim cd As ColorDrawable
    cd.Initialize(Colors.White,15)
    txtContactName.Background=cd
    Activity.AddView(txtContactName, 5%x, 20%y, 85%x, 40dip) 'Left, Top, Width, Height
    
    lblBandName.Initialize("lblBandName")
    lblBandName.Color = Colors.Black
    lblBandName.TextSize = LabelTextSize
    lblBandName.TextColor = Colors.White
    lblBandName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    lblBandName.Text = "BAND NAME"
    Activity.AddView(lblBandName, 5%x, 25%y, 85%x, 5%y) 'Left, Top, Width, Height    

    txtbandName.Initialize("txtBandName")
    txtbandName.TextSize = 20
    txtbandName.TextColor = Colors.Black
    txtbandName.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    txtbandName.Text = ""
    Dim cd As ColorDrawable
    cd.Initialize(Colors.White,15)    
    txtbandName.Background=cd
    Activity.AddView(txtbandName, 5%x, 30%y, 85%x, 40dip) 'Left, Top, Width, Height    

    lblTelephone.Initialize("lblTelephone")
    lblTelephone.Color = Colors.Black
    lblTelephone.TextSize = LabelTextSize
    lblTelephone.TextColor = Colors.White
    lblTelephone.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    lblTelephone.Text = "TELEPHONE NO."
    Activity.AddView(lblTelephone, 5%x, 35%y, 85%x, 5%y) 'Left, Top, Width, Height    

    txtTelephone.Initialize("txtTelephone")
    txtTelephone.TextSize = 20
    txtTelephone.TextColor = Colors.Black
    txtTelephone.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    txtTelephone.Text = ""
    Dim cd As ColorDrawable
    cd.Initialize(Colors.White,15)    
    txtTelephone.Background=cd
    Activity.AddView(txtTelephone, 5%x, 40%y, 85%x, 40dip) 'Left, Top, Width, Height        
    
    lblPostcode.Initialize("lblPostcode")
    lblPostcode.Color = Colors.Black
    lblPostcode.TextSize = LabelTextSize
    lblPostcode.TextColor = Colors.White
    lblPostcode.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    lblPostcode.Text = "POSTCODE"
    Activity.AddView(lblPostcode, 5%x, 45%y, 85%x, 5%y)
    
    txtPostcode.Initialize("txtPostcode")
    txtPostcode.TextSize = 20
    txtPostcode.TextColor = Colors.White
    txtPostcode.Gravity = Gravity.LEFT + Gravity.CENTER_VERTICAL
    txtPostcode.Text = ""
    Dim cd As ColorDrawable
    cd.Initialize(Colors.White,15) 
    txtPostcode.Background=cd
    Activity.AddView(txtPostcode, 5%x, 50%y, 40%x, 40dip)    
End Sub
Best regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…