Spanish [Solucionado] Clase CustomView con dos paneles

angel_

Well-Known Member
Licensed User
Estoy tratando de crear un CustomView de forma que al pulsar un botón se creen dos paneles y en uno de ellos cargo una imagen, pero no consigo que se visualicen.

B4X:
#DesignerProperty: Key: ColorPnl1, DisplayName: Background Color, FieldType: Color, DefaultValue: 0xFF6CB0B0, Description: Color fondo
#DesignerProperty: Key: ColorPnl2, DisplayName: Background Color, FieldType: Color, DefaultValue: 0xFF00FFFF, Description: Color fondo

Sub Class_Globals
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Public xBase As B4XView
   
    Private xui As XUI 'ignore
    Public Tag As Object
   
    Private mLeft, mTop, mWidth, mHeight As Int
    Private pnl1, pnl2 As B4XView
    Private imgElemento As ImageView
    Private ColorPnl1 As Int
    Private ColorPnl2 As Int
    Private ArchivoImg As String
End Sub

Public Sub Initialize (Callback As Object, EventName As String)  
    mEventName = EventName
    mCallBack = Callback
End Sub

'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    xBase = Base
    Tag = xBase.Tag
    xBase.Tag = Me
   
    mLeft = xBase.Left
    mTop = xBase.Top
    mWidth = xBase.Width
    mHeight = xBase.Height
   
    Propiedades(Props)
    IniciarClase
   
    #If B4A
        Base_Resize(mWidth, mHeight)
    #End If  
End Sub

Private Sub IniciarClase
    ArchivoImg = "img.png"
   
    pnl1 = xui.CreatePanel("pnl1")
    xBase.AddView(pnl1, 0, 0, 0, 0)
    pnl1.Color = ColorPnl1
   
    pnl2 = xui.CreatePanel("pnl2")
    xBase.AddView(pnl2, 0, 0, 0, 0)
    pnl2.Color = ColorPnl2
   
    imgElemento.Initialize("")
    imgElemento.Bitmap = LoadBitmap(File.DirAssets, ArchivoImg)
    imgElemento.Gravity = Gravity.Fill
    pnl2.AddView(imgElemento, 0, 0, 0, 0)
End Sub

Private Sub Base_Resize (Width As Double, Height As Double)
    pnl1.SetLayoutAnimated(0, 0, 0, Width / 2, Height)
    pnl2.SetLayoutAnimated(0, pnl1.Left, 0, Width / 2, Height)
    imgElemento.Height = pnl2.Height
    imgElemento.Width = pnl2.Width
    imgElemento.Top = 0
    imgElemento.Left = 0
End Sub

Private Sub Propiedades(Props As Map)
    ColorPnl1 = Props.Get("ColorPnl1")
    ColorPnl2 = Props.Get("ColorPnl2")
End Sub

Public Sub AddToParent(xPanel As B4XView, Left As Int, Top As Int, Width As Int, Height As Int)
    mLeft = Left
    mTop = Top
    mWidth = Width
    mHeight = Height
   
    xBase = xui.CreatePanel("xBase")
    xPanel.AddView(xBase, mLeft, mTop, mWidth, mHeight)

    IniciarClase
End Sub
 

Attachments

  • TestClasss.zip
    20.1 KB · Views: 111

angel_

Well-Known Member
Licensed User
Al final he desistido de crear el CustomView, como lo que necesito es crear el View mediante código (en ningún momento se va a utilizar el Designer), simplemente he creado un clase similar al código pero algo más sencillo y funciona sin problemas.
 
Top