H Haris Hafeez Active Member Licensed User Longtime User Jan 13, 2017 #1 Hello All, I've been having an odd issue with anchors in a layout. In my understanding, the anchors are relative to the containing view or activity. This is not happening in my project and I have reproduced this in my test project, attached here. One thing I do want to mention is that my app uses AHViewPager and this is to blame I think. Can someone please take a look and let me know what might be causing this when used in AHViewPager? Is there a workaround? Layout screenshot: Screenshot of the layout on runtime in the app: Kind Regards, Haris. Attachments upload_2017-1-13_19-11-53.png 36.6 KB · Views: 630 AnchorsPanel.zip AnchorsPanel.zip 88.3 KB · Views: 565
Hello All, I've been having an odd issue with anchors in a layout. In my understanding, the anchors are relative to the containing view or activity. This is not happening in my project and I have reproduced this in my test project, attached here. One thing I do want to mention is that my app uses AHViewPager and this is to blame I think. Can someone please take a look and let me know what might be causing this when used in AHViewPager? Is there a workaround? Layout screenshot: Screenshot of the layout on runtime in the app: Kind Regards, Haris.
DonManfred Expert Licensed User Longtime User Jan 14, 2017 #2 Have you tried it on a real device? Upvote 0
H Haris Hafeez Active Member Licensed User Longtime User Jan 14, 2017 #3 Yes and the result was the same. I've only been working on Android 6.1 emulator and 7.1 device. One thing I will check is if the view pager sets its width as multiple of the screen width based on the number of pages. Still a guess at this point as I'm away from my work place at the moment. Upvote 0
Yes and the result was the same. I've only been working on Android 6.1 emulator and 7.1 device. One thing I will check is if the view pager sets its width as multiple of the screen width based on the number of pages. Still a guess at this point as I'm away from my work place at the moment.
corwin42 Expert Licensed User Longtime User Jan 14, 2017 #4 The problem is that you load the layout too early. In your code, when you add the panel to the pagecontainer the pagecontainer isn't even attached to the ViewPager so the Panel has no dimensions. The correct time to load a layout for the page is in the ViewPager_PageCreated event. Be sure to remove all Views from the page panel again in the ViewPager_PageDestroyed event or if you want to cache the pages make sure that you load them only once in PageCreated. Code: Sub VP_PageCreated (Position As Int, Page As Object) Dim p As Panel = Page p.LoadLayout("ContentLayout") End Sub Sub VP_PageDestroyed (Position As Int, Page As Object) Dim p As Panel = Page p.RemoveAllViews End Sub Last edited: Jan 14, 2017 Upvote 0
The problem is that you load the layout too early. In your code, when you add the panel to the pagecontainer the pagecontainer isn't even attached to the ViewPager so the Panel has no dimensions. The correct time to load a layout for the page is in the ViewPager_PageCreated event. Be sure to remove all Views from the page panel again in the ViewPager_PageDestroyed event or if you want to cache the pages make sure that you load them only once in PageCreated. Code: Sub VP_PageCreated (Position As Int, Page As Object) Dim p As Panel = Page p.LoadLayout("ContentLayout") End Sub Sub VP_PageDestroyed (Position As Int, Page As Object) Dim p As Panel = Page p.RemoveAllViews End Sub
H Haris Hafeez Active Member Licensed User Longtime User Jan 15, 2017 #5 Thanks for pointing out this mistake. Much appreciated! Upvote 0