[SOLVED] How to rotate a Module ? lazarus / 43-Android ---------------------------------------------------------------------- tintinux · 2016-06-16 12:36 Hi In the attached example, made with LAMW, the main panel (in blue) should contain a square as large as possible. To achieve this I would like to have the 2 buttons in the bottom when the orientation is Portrait, and on the right side when it is Landscape. I tried to change the relative position of the buttons when the orientation is changed. Unfortunately, in Landscape orientation, the second button position is not changed and it always remains hidden by the first button. I have tried various things like UpdateLayout and ResetAllRules, without result. I'm certainly missing something, but I do not find what... Can you help me ? Thanks ! ---------------------------------------------------------------------- jmpessoa · 2016-06-17 08:32 Hello tintinux! Here is a possible solution: "unit1.lfm" Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object AndroidModule1: TAndroidModule1  Left = 268  Top = 152  Width = 320  Height = 523  MarginLeft = 0  MarginTop = 0  MarginRight = 0  MarginBottom = 0  Text = 'AndroidModule1'  ActivityMode = actMain  BackgroundColor = colbrDefault  ActionBarTitle = abtDefault  OnRotate = AndroidModule1Rotate  object jPanel1: jPanel    Left = 4    Top = 4    Width = 308    Height = 404    MarginLeft = 4    MarginTop = 4    MarginRight = 4    MarginBottom = 4    Visible = True    PosRelativeToAnchor = []    PosRelativeToParent = [rpTop]    LayoutParamWidth = lpMatchParent    LayoutParamHeight = lpFourFifthOfParent    BackgroundColor = colbrSkyBlue    MinPinchZoomFactor = 0.25    MaxPinchZoomFactor = 4    Id = 5954533  end  object jPanel2: jPanel    Left = 4    Top = 416    Width = 308  Height = 90    MarginLeft = 4    MarginTop = 4    MarginRight = 4    MarginBottom = 4    Visible = True    Anchor = jPanel1    PosRelativeToAnchor = [raBelow]    PosRelativeToParent = []    LayoutParamWidth = lpMatchParent    LayoutParamHeight = lpOneFifthOfParent    BackgroundColor = colbrLightGreen    MinPinchZoomFactor = 0.25    MaxPinchZoomFactor = 4    Id = 0    object jPanel3: jPanel      Left = 4      Top = 4      Width = 140    Height = 48      MarginLeft = 4      MarginTop = 4      MarginRight = 4      MarginBottom = 4      Visible = True      PosRelativeToAnchor = []      PosRelativeToParent = [rpTop]      LayoutParamWidth = lpHalfOfParent      LayoutParamHeight = lpWrapContent      BackgroundColor = colbrSilver      MinPinchZoomFactor = 0.25      MaxPinchZoomFactor = 4      Id = 5672351      object jButton1: jButton        Left = 4        Top = 4        Width = 132        Height = 40        MarginLeft = 2        MarginTop = 4        MarginRight = 2        MarginBottom = 4        Visible = True        PosRelativeToAnchor = []        PosRelativeToParent = [rpCenterInParent]        LayoutParamWidth = lpMatchParent        LayoutParamHeight = lpWrapContent        Text = 'jButton1'        BackgroundColor = colbrDefault        FontColor = colbrDefault        FontSize = 0        FontSizeUnit = unitDefault        Id = 0      end    end    object jPanel4: jPanel      Left = 152      Top = 4      Width = 140      Height = 48      MarginLeft = 4      MarginTop = 4    MarginRight = 4      MarginBottom = 4      Visible = True      Anchor = jPanel3      PosRelativeToAnchor = [raToRightOf, raAlignBaseline]      PosRelativeToParent = []      LayoutParamWidth = lpHalfOfParent      LayoutParamHeight = lpWrapContent      BackgroundColor = colbrSilver      MinPinchZoomFactor = 0.25      MaxPinchZoomFactor = 4      Id = 3763529      object jButton2: jButton        Left = 4        Top = 4        Width = 132        Height = 40        MarginLeft = 2        MarginTop = 4        MarginRight = 2        MarginBottom = 4        Visible = True        PosRelativeToAnchor = []        PosRelativeToParent = [rpCenterInParent]        LayoutParamWidth = lpMatchParent        LayoutParamHeight = lpWrapContent        Text = 'jButton2'        BackgroundColor = colbrDefault        FontColor = colbrDefault        FontSize = 0        FontSizeUnit = unitDefault        Id = 0      end    end  endend  "Unit1.pas" Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit unit1; {$mode delphi} interface uses  Classes, SysUtils, And_jni, And_jni_Bridge, Laz_And_Controls,     Laz_And_Controls_Events, AndroidWidget; type   { TAndroidModule1 }   TAndroidModule1 = class(jForm)    jButton1: jButton;    jButton2: jButton;    jPanel1: jPanel;    jPanel2: jPanel;    jPanel3: jPanel;    jPanel4: jPanel;  procedure AndroidModule1Rotate(Sender: TObject; rotate: TScreenStyle);  private    {private declarations}  public    {public declarations}  end; var  AndroidModule1: TAndroidModule1; implementation {$R *.lfm}   { TAndroidModule1 } procedure TAndroidModule1.AndroidModule1Rotate(Sender: TObject;  rotate: TScreenStyle);begin   case  rotate of     ssLandscape:     begin        jPanel3.LayoutParamWidth:= lpMatchParent;       jPanel3.PosRelativeToParent:= [rpTop];        jPanel4.LayoutParamWidth:= lpMatchParent;       jPanel4.PosRelativeToAnchor:= [raBelow];        jPanel1.LayoutParamHeight := lpMatchParent;       jPanel1.LayoutParamWidth := lpThreeQuarterOfParent;       jPanel1.PosRelativeToParent := [rpLeft];        jPanel2.LayoutParamHeight := lpMatchParent;       jPanel2.LayoutParamWidth := lpOneQuarterOfParent;       jPanel2.PosRelativeToAnchor := [raToRightOf, raAlignBaseline];      end;     ssPortrait:     begin        jPanel3.LayoutParamWidth:= lpHalfOfParent;       jPanel3.PosRelativeToParent:= [rpTop];        jPanel4.LayoutParamWidth:= lpHalfOfParent;       jPanel4.PosRelativeToAnchor:= [raToRightOf,raAlignBaseline];         jPanel1.LayoutParamHeight := lpFourFifthOfParent;       jPanel1.LayoutParamWidth := lpMatchParent;       jPanel1.PosRelativeToParent := [rpTop];        jPanel2.LayoutParamHeight := lpOneFifthOfParent;       jPanel2.LayoutParamWidth := lpMatchParent;       jPanel2.PosRelativeToAnchor := [raBelow];      end;  end;   if rotate in [ssLandscape, ssPortrait] then  begin     jPanel1.ResetAllRules;  jPanel2.ResetAllRules;    jPanel3.ResetAllRules;    jPanel4.ResetAllRules;     Self.UpdateLayout;  end; end; end. ---------------------------------------------------------------------- tintinux · 2016-06-20 09:55 Hi Thanks for the idea, it works with each button over it's panel, but it is a little tedious... Isn't it possible and simpler to make jButton.ResetAllRules a public method ?  Or maybe even to make public the jVisualControl ancestor method ? Best regards ---------------------------------------------------------------------- jmpessoa · 2016-06-20 22:10 QuoteIsn't it possible and simpler to make jButton.ResetAllRules a public method ?  Or maybe even to make public the jVisualControl ancestor method ? Yes! I will try some improvement to rotate! Thank you!