I have a layout with a toolbar and a view that will host other controls:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ViewStub
android:id="@+id/root_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
A FrameLayout is used so that the toolbar, which has a positive "elevation", can be translucent and the view extends to under the toolbar. The toolbar and the view have the same top position but different height. When Talkback builds the view hierarchy, it puts the toolbar at the bottom even though it's defined first. "accessibilityTraversalBefore" and "accessibilityTraversalAfter" on the views have no effect. The only solution I found so far was to add a top margin of 1px or 0.1px to the ViewStub. This probably has something to do with the code here:
The code tries to reorder the nodes based on their screen positions. Adding the top margin is a bit hacky and may break some day. Is there a better solution?