如何防止MultiView不透明度影响Delphi中的子组件文本?

时间:2017-12-01 02:24:29

标签: delphi firemonkey opacity

我在Firemonkey中使用MultiView和一些TButton按钮。多视图在0.5时是不透明的,这会导致按钮也不透明。

问题:有没有办法阻止MultiView不透明度影响按钮文本?也就是说,按钮的文本将继续使用鲜艳的颜色,但" body"按钮是不透明的。我已经看到了一些具有此视觉功能的应用程序,但我不知道为此目的使用了哪些组件......

enter image description here

2 个答案:

答案 0 :(得分:2)

使用TMultiView作为菜单的基础,而不是TRectangle。将其Align设置为左侧,将Fill.Color设置为$7FFFFFFF。两个第一个十六进制数字(7F)定义alpha通道(半透明),其余的十六进制数字(FFFFFF)定义RGB颜色。这允许您将Opacity保留为一个,但仍具有半透明效果。使用TMultiView控件无法做到这一点。

对于每件商品,请使用TLayoutTImageTText以及您喜欢的任何分隔线。使用普通Align属性设置项目。

最后,为HitTest = True设置TLayout,为HitTest = FalseTImage控件设置TText。这是为了启用鼠标点击或点击。

以下是我的测试,包括.fmx内容(已移除图像数据)和快照。

  object Rectangle1: TRectangle
    Align = Left
    Fill.Color = x7FFFFFFF
    Size.Width = 200.000000000000000000
    Size.Height = 210.000000000000000000
    Size.PlatformDefault = False
    object Layout1: TLayout
      Align = Top
      HitTest = True
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
      object Image1: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs\0.bmp'
          end>
        Align = Left
      end
      object Text4: TText
        Align = Left
        Position.X = 50.000000000000000000
        Size.Width = 151.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'Zero Hero'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
    object Layout2: TLayout
      Align = Top
      HitTest = True
      Position.Y = 50.000000000000000000
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 1
      object Image2: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs\1.bmp'
          end>
        Align = Left
      end
      object Text5: TText
        Align = Left
        Position.X = 50.000000000000000000
        Size.Width = 151.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'One More'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
    object Layout3: TLayout
      Align = Top
      HitTest = True
      Position.Y = 100.000000000000000000
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 2
      OnClick = Layout3Click
      OnMouseDown = Layout3MouseDown
      object Image3: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs\2.bmp'
          end>
        Align = Left
        HitTest = False
      end
      object Text6: TText
        Align = Left
        HitTest = False
        Position.X = 50.000000000000000000
        Size.Width = 150.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'Double Joy'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
    object Layout4: TLayout
      Align = Top
      HitTest = True
      Position.Y = 150.000000000000000000
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 3
      object Image4: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs\3.bmp'
          end>
        Align = Left
        HitTest = False
      end
      object Text1: TText
        Align = Left
        HitTest = False
        Position.X = 50.000000000000000000
        Size.Width = 151.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'Triple Fun'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
  end

enter image description here

答案 1 :(得分:0)

我认为你不能。但是,您可以通过将空白按钮作为多视图的子项并添加单独的TText对象作为表单的子项(或绝对不透明度为1的其他对象)来实现效果,如下面的屏幕截图所示。例如,如果按钮可以移动或调整大小,这是不理想的,但是这可以通过创建TPanel来实现,使Multiview和文本分离出来,然后使用面板进行移动和调整大小的目的,将确保按钮及其相关文本保持一致。

enter image description here

修改

根据Tom Brunsberg的评论,我建议让他们成为TPanel的孩子,而不是TForm。当然,在我的测试中,他提到TText后面的问题在完成时不会发生。对于TText对象,将HitTest设置为false是完全正确的。