I like the idea of using RelativeLayout as an alternative to many LinearLayouts, but it seems to fall short in a couple of areas.
- Its behavior for child views that have
visibility=gone
is atrocious. It seems like the natural behavior for gone views would be to treat them as if they had width and height of 0, but instead it removes them as anchors and any other views that are laid out relative to the gone views get put in开发者_如何学JAVA unpredictables places. Yes, it's possible to use "layout_alignWithParentIfMissing" to work around some of these issues, but that's not really the same thing, is it? - It doesn't support the
layout_weight
option that I find so useful in LinearLayout.
Are there any good alternatives to RelativeLayout out in the wild that solve these or similar problems?
You can use nested layouts with Relative Layout.
<RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<widget>
<Widget>
</LinearLayout>
<TableLayout
android:layout_alignParentTop="true">
<TableRow>
<Widget>
<Widget>
</TableRow>
<Widget> // By itself in the middle of a table layout
</TableLayout>
</RelativeLayout>
Just a very simplistic example. Any container type can be nested inside of a RelativeLayout, but ScrollView can only have 1 direct child.
精彩评论