开发者

Alternatives to RelativeLayout?

开发者 https://www.devze.com 2023-02-15 09:48 出处:网络
I like the idea of using RelativeLayout as an alternative to many LinearLayouts, but it seems to fall short in a couple of areas.

I like the idea of using RelativeLayout as an alternative to many LinearLayouts, but it seems to fall short in a couple of areas.

  1. 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?
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消